1obj array[] = new obj[10];
2
3for (int i = 0; i < array.length; i++) {
4 array[i] = new obj(i);
5}
1class Main{
2 public static void main(String args[]){
3 //create array of employee object
4 Employee[] obj = new Employee[2] ;
5
6 //create & initialize actual employee objects using constructor
7 obj[0] = new Employee(100,"ABC");
8 obj[1] = new Employee(200,"XYZ");
9
10 //display the employee object data
11 System.out.println("Employee Object 1:");
12 obj[0].showData();
13 System.out.println("Employee Object 2:");
14 obj[1].showData();
15 }
16}
17//Employee class with empId and name as attributes
18class Employee{
19 int empId;
20 String name;
21 //Employee class constructor
22 Employee(inteid, String n){
23 empId = eid;
24 name = n;
25 }
26public void showData(){
27 System.out.print("EmpId = "+empId + " " + " Employee Name = "+name);
28 System.out.println();
29 }
30}
1//create class
2class enemies {
3 int marks;
4}
5//create object array
6enemies[] enemiesArray = new enemies[7];
7//assign value to object
8enemiesArray[5] = new enemies(95);