Question
1.Assume you have a base class Superclass, and class Subclass that extends Superclass. If you have the following code: Superclass c = new Subclass(); will
1.Assume you have a base class Superclass, and class Subclass that extends Superclass. If you have the following code: Superclass c = new Subclass(); will this cause an error? (Assume Subclass has a default constructor). Why or why not?
2. For the classes Superclass and Subclass as described above, which is true:
A Superclass is a Subclass
A Subclass is a Superclass
Both of these
Neither of these.
3. Now assume you have classes Person and Student as defined in class. Assume that you have a Person type variable that references a Student type object. I.e. Person p = new Student(Sally, 18); If the method sayHi() is defined in the Person class and overridden in the student class, which version of the method will be called when I write p.sayHi(), the Persons version or the Students version?
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