Final Exam Inheritance Questions

1. Suppose the class named SportsCar is a subclass of a class called Automobile. Suppose the class Automobile has instance variables named speed, manufacturer, and numberOfCylinders. Will an object of the class SportsCar have instance variables named speed, manufacture, and numberOfCylinders? 

2. Suppose the class named SportsCar is a subclass of a class called Automobile, and suppose the class Automobile has public methods named accelerate and addGas. Will an object of the class SportsCar have methods named accelerate and addGas? If so, do these methods have to perform the exact same actions in the class SportsCar as in the class Automobile?

3. If you are defining a subclass, can you dirctly access a private instance variable of the superclass?

4. If you are defining a derived class, can you use a private method of the superclass?

5. Give the complete definition of a class called TitledPerson. TitledParson is to be a subclass of the class Person from the lecture notes. The class TitledPeson has one additional String instance variable for a title, such as "Ms", "Mr.", or "The Honorable". The class TitledPerson has two constructors, a default constructor and one that sets both the name and the title. It has a writeOutput method, a reset method, an equals method, an accessor method getTitle that returns the title, and a mutator method setTitle that changes the person's title. For two titled people to be equal, they must have the same name and the same title.

6. What is the difference between this and super when these words are used as the names of methods that are called in a constructor definition.

7. Which of the following lines are legal and which are illegal?

	Person p1 = new Student("Kael", 4444);
	Person p2 = new CoopStudent("Mike", 1234);
	Student s1 = new Person("Marcus");
	Student s2 = new CoopStudent("Chantelle", 3242);
	CoopStudent c1 = new Person("Kael");
	Coopstudent c2 = new Student("Mike, 1234);
	Object o = new Student("Marcus", 3142);
	Student s3 = new Object();

8. What is the difference between overriding a method name and overloading a method name?