QUIZ

CHAPTER 9

Your Name:


9.1 If we wish to add a gestation period to the Nature hierarchy, in which class(es) would it logically go?

(a) Nature
(b) Animals
(c) Elephant and Rhino
(d) Herbivores

9.2 TestNature is prevented from seeing the variable name inside class Nature because

(a) name is protected
(b) Nature has not been instantiated in TestNature
(c) Nature is a superclass of Elephant and Rhino, not a subclass
(d) name has not been initialized

9.3 In the Nature hierarchy, the toString method is an example of

(a) overriding
(b) overloading
(c) shadowing
(d) dynamic binding

9.4 If we wanted to sort the coffee list from Example 8.2,

(a) we could do it by implementing Sortable
(b) we could do it by implementing Sortable and defining a lessThan method
(c) we could not do it because selectionSort works on arrays only
(d) we could not do it because we cannot define a lessThan method between two list objects

9.5 If a is an Animal object, then it has the following data variables:

(a) name
(b) name and grassNeeded
(c) none
(d) name, grassNeeded and either tusks or horn

9.6 The rule for working within a hierarchy, expressed in terms of P and Q where Q extends P is:

(a) Q can be assigned to P
(b) P can be assigned to Q with a type cast
(c) both A and B
(d) neither A nor B

9.7 The following is an attempt to implement a lessThan method for comparing Rhinos' horns:

public boolean lessThan (Sortable a) {
return horn < a.horn;
}

It will not compile because:

(a) horn is private
(b) a does not necessarily have a horn
(c) < is not defined for double variables
(d) lessThan has already been defined for tusks

9.8 To read a hash table object, hash, back that has been written to a file (assuming that a correct connection has been made to an object stream oos), we use:

(a) hash = (HashTable) oos.readObject();
(b) hash = (Serializable) oos.readObject();
(c) hash = oos.readObject();
(d) hash = new readObject ();

9.9 If the serializable process raises a ClassNotFoundException, then a likely cause is:

(a) the class was not compiled
(b) the class was not instantiated
(c) the class was not declared as implementing Serializable
(d) the class does not exist

9.10 To create an instance of an abstract class we

(a) define any abstract methods then instantiate the class
(b) instantiate the class
(c) instantiate its superclass
(d) call a class method to create the instance