Create an array of type comnunitymember
Then create objects of type (employee, student, faculty) by sending the values to the creator of each class
Store these classes in an array and then print these objects with their type specified using the instanceOf . test
public class Main {
public static void main(String[] args) {
CommunityMember[] members = new CommunityMember[3];
members[0] = new Employee();
members[1] = new Student();
members[2] = new Faculty();
for (int i = 0; i < members.length; i++) {
System.out.print(members[i] + " ");
if (members[i] instanceof Employee) {
System.out.println("Employee");
} else if (members[i] instanceof Student) {
System.out.println("Student");
} else if (members[i] instanceof Faculty) {
System.out.println("Faculty");
}
}
}
}
Comments
Leave a comment