You are on page 1of 1

Chapter 9 Critical Thinking Answers

1.

A has-a relationship is demonstrated by a class that contains another class. An is-a


relationship is demonstrated when a class is derived from an existing class.

2.

Both methods will be available to an object of the derived class.

3.

An abstract method contains a declaration but no body. An abstract method is declared


in an abstract class, and then implemented in a subclass. Overridding redenes an
implemented method from a superclass in a subclass.

4.

An abstract class must be inherited to implement its methods in a subclass. An interface


cannot be inherited, but its methods can be implemented in a class.

5.

The compareTo method is the only method in the Comparable interface.

6.

a) All methods in an interface are public and abstract.


b) Wo is an interface.
c) The doThat() method is implemented in Roo because the methods of an interface must
be dened in the class that implements the methods interface.
d) The methods available to a Roo object are doThis(), doNow(), and doThat().
e) The doThis() implementation in Roo overrides the doThis() implementation in Bo.
f) The statement super(1) in Roo assigns the value 1 to the variable x from Bo.
g) Yes, the doThis() method in Bo can be called from an Roo object if the Roo object
references a Bo object.
h) Yes, a method in Roo can call the doThis() method in Bo by using the keyword super.

7.

a)
b)
c)
d)

True.
False. Classes that are derived from existing classes demonstrate an is-a relationship.
False. A class can have many levels of inheritance.
False. A class that inherits another class includes the keyword extends in the class
declaration.
e) True.
f) False. Members of a base class that are declared private are not accessible to derived
classes.
g) True.
h) True.
i) False. An abstract class cannot be instantiated because they should not represent
objects.
j) True.
k) False. An abstract method does not include a method body.
l) True.
m) False. An interface cannot be inherited.
n) True.
o) False. The methods dened in an interface are public by default.
p) False. The Comparable interface contains one method.

A Guide to Programming in Java, Second Edition


2007 Lawrenceville Press

You might also like