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()); } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter