Answered step by step
Verified Expert Solution
Question
1 Approved Answer
LAB 7: Inheritance and polymorphism Lab 7: Inheritance and polymorphism Our project named Lab7 contains the class main named Inheritance and two classes with the
LAB 7: Inheritance and polymorphism Lab 7: Inheritance and polymorphism Our project named Lab7 contains the class main named Inheritance and two classes with the following members : Question 7.1: In the Person class : a. The first constructor diplays the message "Constructor 1 Person" b. The second constructor initialize the first and the last name of the person and displays the message "Constructor 2 Person " c. readPerson0 method reads the first and the last names from the keyboard. d. ShowPerson0 displays the first and last name of the person. For the Student class : e. The first constructor diplays the message "constructor 1 Student " f. The second constructor uses the keyword super() to initialize the first and the last names. It initializes the grade of the student and also displays the message "constructor 2 Student " g. readStudent 0 method calls readPerson() method to read the first and the last names from the keyboard and reads the grade. h. showStudent() method displays the first and the last names of a student by calling the showPerson() method and shows the grade. In the main method, - Create an instance S1 of Student class with the first constructor, - Call readStudent method for S1, - Display the information of S1. Question 7.2 : In the main method, - Create an instance S2 of Student class with the second constructor ; - Display the information of S2. - Set the first name of S2. To do that, you should add the setFirst(String) method in Person class. - Set the last name of S2. To do that, you should add the setLast(String) method in Person class. - Display again the information of S2. Question 7.3 : 1. In the main method, - Create an instance S3 of Person class having Student as actual type. - Display the information of S3 by calling the toString method with S3. From which class toString method is called? - It is possible to create an instance S4 of Student class having Person as actual type. 2. In the class Person, - The toString method is overriding that returns the first and the last names concatenated. 3. In the main method, - Call readPerson method with S3. - Display the information of S3 by calling the toString method. From which class the toString method is called? 4. In the class Student, - The toString method is overriding that returns the first and the last names (by calling toString from the Person class) and the grade. 5. In the main method, - Call readPerson method with S3. - Display the information of S3 by calling the toString method. From which class the toString method is called
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started