Results 1 to 1 of 1
- 12-12-2011, 11:06 PM #1Member
- Join Date
- Dec 2011
- Rep Power
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.
- By nicholil in forum New To JavaReplies: 2Last Post: 11-07-2010, 02:52 AM
- By Mojito_gr in forum Advanced JavaReplies: 7Last Post: 08-02-2010, 04:47 AM
- By HoChiMinh in forum Java CertificationReplies: 1Last Post: 01-03-2009, 04:27 AM
- By mohkhamis in forum New To JavaReplies: 2Last Post: 10-23-2008, 05:43 PM
- By bri1547 in forum New To JavaReplies: 2Last Post: 08-24-2008, 11:22 PM