public class PersonStudentTest { /** * @param args */ public static void main(String[] args) { Person p = new Person(24, "Thien"); p.speak(); Student s = new Student(28, "Stefani", 3.8); s.speak(); p = s; // OK, since a student is a person // s = p; // NO, since a person is not a student p.speak(); // Group of persons Person[] person = new Person[4]; String[] name = {"Aaron", "Kallista", "Hieu", "Joe"}; for (int i =0; i < person.length; i ++) { int age = 20 + (int) (Math.random() * 30); if (Math.random() < 0.5) { // person person[i] = new Person(age, name[i] ); } else { // student person[i] = new Student(age, name[i], Math.random() + 3); } } // Make the group of persons speak for (int i = 0; i < person.length; i ++) { person[i].speak(); } } }