java class array of objects
public class MainClass
{
public static void main(String args[])
{
System.out.println("Hello, World!");
//step1 : first create array of 10 elements that holds object addresses.
Emp[] employees = new Emp[10];
//step2 : now create objects in a loop.
for(int i=0; i<employees.length; i++){
employees[i] = new Emp(i+1);//this will call constructor.
}
}
}
class Emp{
int eno;
public Emp(int no){
eno = no;
System.out.println("emp constructor called..eno is.."+eno);
}
}
Also in Java:
- java variable declared
- how to use the this keyword in java
- java quit application
- java save string in text file
- boolean java.lang.String.equals(java.lang.Object)' on a null object reference
- abs in java
- Caused by: java.lang.NumberFormatException: Invalid int: ""
- java enum
- java search file in folder
- java prev_permutation
- android hide and show bottom navigation
- integer max value java
- java bean
- java random number
- python to java converter
- hashmaps java
- declare array java inline
- Please ensure that your JAVA_HOME points to a valid Java SDK. You are currently pointing to: /usr/lib/jvm/java-13-oracle
- java if different ways
- java random char a-z
- counting the sequence of character in string java
- spring code in java
- java obtain list string from list object
- java pass array as method parameter