how to create an object of an array in java code example
Example 1: how to make array of objects in java and use it
class enemies {
int marks;
}
enemies[] enemiesArray = new enemies[7];
enemiesArray[5] = new enemies(95);
Example 2: java class array of objects
public class MainClass
{
public static void main(String args[])
{
System.out.println("Hello, World!");
Emp[] employees = new Emp[10];
for(int i=0; i<employees.length; i++){
employees[i] = new Emp(i+1);
}
}
}
class Emp{
int eno;
public Emp(int no){
eno = no;
System.out.println("emp constructor called..eno is.."+eno);
}
}