Process of Adding on object to an array list/Hashmap

PHOTO EMBED

Sat Apr 13 2024 11:18:25 GMT+0000 (Coordinated Universal Time)

Saved by @Divya ##array

class Person {
       private String name;
        private int age;
        
        public  Person (String name, int age){
            this.name = name;
            this.age = age;
        }
        
    }

public static void main(String[] args) {
       Person[] person = new Person[3];
       
      person[0] = new Person("Divya", 21);
       person[1] = new Person("Naresh", 23);
       person[2] = new Person("Nivethi", 20);
        
        for(int i=0; i< person.length ; i++)
{
    System.out.println(" " + person.getAge());
}       
    }

content_copyCOPY

Gigame Portal