final study guide - compile and run-time types, and inheritance
Hello, I am new to java and i have a final tomorrow. Since my professor has closed his email to questions I was hoping to get help here.
If I have classes Student and Employee that extend class Person, is this statement legal or not?
Employee z = new Person();
My answer is that it is illegal because a reference variable can only refer to objects in it's class or any sub class. Employee has methods that are not defined for person. I would like to be well versed in the correct terminology. Can someone help with that?
Also i am supposed to list the compile and run-time types for the following variables:
a) Person a = new Person();
b) Person b = new Student();
c) Student c = new Student();
d) Employee d = new Employee();
e) Person e = new Employee();
Is it correct to say that the compile time type is the left hand side of each expression and the right hand side is the run-time type? That answer of course only would apply in this case, and not in general. Thanks for the help.