Consider the following classes public class Teacher public

Consider the following classes:

public class Teacher {...}

public class Lecturer extends Teacher {...}

public class Professor extends Teacher {...}

Which of the following would be legal statements?

1. Teacher t = new Lecturer();

2. Teacher t = new Professor();

3. Lecturer l = new Professor();

4. Professor p = new Professor();

5. Professor p = new Teacher();

6. Lecturer l = new Teacher();

Solution

Answer: 1,2 and 4

Below are the legal statements

1. Teacher t = new Lecturer();

2. Teacher t = new Professor();

4. Professor p = new Professor();

We can not instantiated the child object with parent object reference. But we can instantiated the parent object with child object reference.

Consider the following classes: public class Teacher {...} public class Lecturer extends Teacher {...} public class Professor extends Teacher {...} Which of the

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site