Question: Write a Java program that demonstrates inheritance and Polymorphism. For this purpose, you are required to create a parent class and 2 child classes as
Write a Java program that demonstrates inheritance and Polymorphism. For this purpose, you are required to create a parent class and 2 child classes as follows:
The main method is provided to you below. You are required to create two methods namely display() and getCount() in Driver.java file that would display all the results and count number of students and faculty in the given array respectively.
main method:
public static void main(String[] args)
{
Person persons[] = new Person[]{
new Student("Steve Jobs", "71 Simcoe Road", "111-111-1111", "steve@uoit.ca", "Freshman"),
new Student("BilL Gates", "100 College Creek", "111-121-1221", "bill@uoit.ca", "Sophomore"),
new Student("Elon Musk", "120 Simcoe Avenue", "786-111-7789", "elon@uoit.ca", "Freshman"),
new Student("Mark Wood", "2041 Davis Drive", "888-121-4111", "mark@uoit.ca", "Jnuior"),
new Student("Jack Ma", "68 Markham Road", "333-111-4444", "jack@uoit.ca", "Senior"),
new Student("Muhammad Khan", "29 Richmod Crescent", "111-000-2511", "muhammad@uoit.ca", "Freshman"),
new Student("Aleena Shah", "51 Simcoe Road", "666-777-8888", "aleena@uoit.ca", "Senior"),
new Student("Shakira Kin", "29 Toronto Road", "888-111-7771", "shakira@uoit.ca", "Junior"),
new Student("Laura Tim", "100 Prince Road", "999-000-1111", "laura@uoit.ca", "Freshman"),
new Faculty("Jasson Wood", "Davis Drive", "121-000-2222", "jasson@uoit.ca", "Assistant Professor"),
new Faculty("Tim David", "81 Toronto Yard", "121-222-8882", "tim@uoit.ca", "Associate Professor"),
new Faculty("Louis James", "131 James Avenue", "444-5552-4522", "louis@uoit.ca", "Assistant Professor"),
new Faculty("Tony Greg", "3331 King Avenue", "662-111-2999", "tony@uoit.ca", "Professor"),
new Faculty("Lizzy King", "881 Wilson Street", "777-666-0000", "lizzy@uoit.ca", "Associate Professor"),
new Faculty("Paula James", "101 Golden Road", "777-111-2000", "paula@uoit.ca", "Professor")
};
display(persons);
getCount(persons);
}
Expected Output:

Person class (Parent) Should have following instance members: O Should have following member functions and parameterized constructor Person(String name, string address, String phone Number, String email) public String toString() returns all instance variables in a single string I String name; String address; string phoneNumber; String email; Student class (child of Person) oShould have following instance member: String status; - Freshman/Sophomore/Junior/Senior Should have following member functions and parameterized constructor I I Student(String name, String address, String phone Number, String email, String status) public String tostring() - returns all instance variables in a single string (don't forget to call tostring of parent class in this method to avoid writing previously written instance variables of Person class) Faculty class (child of Person) Should have following instance member: String rank; - Assistant Professor/Associate Professor/Professor Should have following member functions and parameterized constructor Faculty(String name, String address, String phone Number, String email, String rank) public String toString() - returns all instance variables in a single string (don't forget to call tostring of parent class in this method to avoid writing previously written instance variables of Person class)
Step by Step Solution
3.34 Rating (151 Votes )
There are 3 Steps involved in it
Step 1 The question ask to implement class Person and class Student and Faculty which inherits class Person Each class must have parameterized constructor and a toString method the question also asks ... View full answer
Get step-by-step solutions from verified subject matter experts
