saving . . . saved Conceptual Question has been deleted. Conceptual Question has been hidden .
Conceptual Question
Dear Sir, 
Can you please explain me why is the setDepartment() not valid for statment " Employee emp2= new Manager();". Why is it not taking the vaue that is given in the TestManager class.Sir can you please tell me about the exam after this course?
Hoping at the earliest!

Java Polymorphism 04-05 min 30-40 sec 07-12-21, 10:23 p.m. Psych_Scientist



To know about the exam, please do write on my email id with following details, we will help you.

1. Full name-
2. College name-
3. Email id- 
4. Phone number- 

Thanks and Regards,
Diana Low

03-01-22, 12:39 p.m. Diana21
When you create child class object with the reference variable of the parent class, the reference variable allows you to access member variables and methods that belong to class type of reference variable only. 

You have created "Manager" class object and assigned it the reference of the parent class, i.e. "Employee". As "emp2" is the reference variable of the "Employee" class, using "emp2" reference you can access the members of the Employee class only.   Thus, in your case using reference variable "emp2", you will be able to access variables and methods of Employee class only.

As "setDepartment" method doesn't belong to Employee class it is non-accessible by "emp2" variable.
04-01-22, 12:27 p.m.

Login to add comment

Log-in to answer to this question.