#
31. The relationship between an interface and the class that implements it is .
a. Composition
b. Aggregation
c. Inheritance
d. None
#
Section 13.9 Case Study: The Rational Class
32. The Rational class in this chapter is defined as a subclass of java.lang.Number. Which of the following
expressions is correct?
a. Rational.doubleValue();
b. Rational.doubleValue(“5/4”);
c. new Rational(5, 4).doubleValue();
d. new Rational(5, 4).toDoubleValue();
e. new Rational(5, 4).intValue();
#
33. The Rational class in this chapter extends java.lang.Number and implements java.lang.Comparable. Analyze the
following code.
1. public class Test {
2. public static void main(String[] args) {
3. Number[] numbers = {new Rational(1, 2), new Integer(4), new Double(5.6)};
4. java.util.Arrays.sort(numbers);
5. }
6. }
a. The program has a compile error because numbers is declared as Number[], so you cannot assign {new
Rational(1, 2), new Integer(4), new Double(5.6)} to it.
b. The program has a runtime error because numbers is declared as Number[], so you cannot assign {new
Rational(1, 2), new Integer(4), new Double(5.6)} to it.
c. The program has a compile error because numbers is declared as Number[], so you cannot pass it to
Arrays.sort(Object[]).
d. The program has a runtime error because the compareTo methods in Rational, Integer, and Double classes do not
compare the value of one type with a value of another type.
#
Section 13.10 Class Design Guidelines
34. Which of the following statements are true?
a. A class should describe a single entity and all the class operations should logically fit together to support a coherent
purpose.
b. A class should always contain a no–arg constructor.
c. The constructors must always be public.