Java Reference
In-Depth Information
Answers to Review Questions
1.
Inheritance.
2.
A rectangle is not a triangle, so the is a relationship is not satisfied.
3.
True. Child classes inherit all fields from their parent class, no matter what the access
specifier of a parent field is.
4.
Except for the constructor in the Object class, this statement is true.
5.
False. The only call the compiler adds is super() if this() or super() does not appear
explicitly.
6.
java.lang.Object.
7.
False. Multiple inheritance is not allowed in Java, so a Java class can only have one
parent.
8.
The statement super(w) must be the first line of code in the Car constructor. Move it
to before the numOfDoors = d statement, and the class will work fine.
9.
Neither of those two statements compiles. The statement new Car() implies that the
Car class has a no-argument constructor, but it does not. The statement Car.drive()
tries to invoke drive() using the name of the class, which does not make any sense.
10.
The output is “Driving a car.”
11.
The output is “Driving a vehicle” for the first two statements. The third statement does
not compile. A Vehicle object does not have a field of type numOfDoors.
Search WWH ::




Custom Search