Introduction to Java Programming, Seventh Edition, Y. Daniel Liang

Chapter 12 Object-Oriented Modeling


Section 12.2 Software Life Cycle
1  _____________ is a formal process that seeks to understand the problem and document in detail what the software system needs to do.

A. Requirements specification
B. Analysis
C. Design
D. Implementation
E. Testing

2  _________ is to identify the classes and discover the relationships among these classes.

A. Coding
B. Testing
C. Designing classes
D. Requirements specification

Section 12.3 Discovering Classes
3  In a CRC index card,

A. write the class name at the top of the card.
B. each row has two columns.
C. Write a responsibility on the left column.
D. write it in the corresponding right column if the responsibility involves a collaborator class.

Section 12.4 Discovering Class Relationships
4  _________ is a general binary relationship that describes an activity between two objects.

A. Association
B. Aggregation
C. Composition
D. Inheritance

5  __________ is a special form of association that represents an ownership relationship between two objects.

A. Association
B. Aggregation
C. Composition
D. Inheritance

6  __________ represents an exclusive ownership relationship between two objects.

A. Association
B. Aggregation
C. Composition
D. Inheritance

7  __________ models the is-a relationship between two classes.

A. Association
B. Aggregation
C. Composition
D. Inheritance

8  __________ describes dependent relationships between two classes.

A. Association
B. Aggregation
C. Composition
D. Dependency

9  _________ can be viewed as a special case of _____________.

A. Association/dependency
B. Dependency/association

10  ___________ is attached to the class of the composing class to denote the aggregation relationship with the composed object.

A. An empty diamond
B. A solid diamond
C. An empty oval
D. A solid oval

11  An aggregation relationship is usually represented as __________ in ___________.

A. a data field/the aggregating class
B. a data field/the aggregated class
C. a method/the aggregating class
D. a method/the aggregated class

12  Which of the following statements are true?

A. Inheritance models the is-a relationship between two classes.
B. A strong is-a relationship describes a direct inheritance relationship between two classes.
C. A weak is-a relationship describes that a class has certain properties.
D. A strong is-a relationship can be represented using class inheritance.
E. A weak is-a relationship can be represented using interfaces.

13  Assume an employee can work for only one company. What is the best suitable relationship between Company and Employee?

A. Association
B. Aggregation
C. Inheritance
D. Composition

14  A faculty teaches a course. What is the best suitable relationship between Faculty and Course?

A. Association
B. Aggregation
C. Inheritance
D. Composition

15  What is the best suitable relationship between Employee and Faculty?

A. Association.
B. Aggregation.
C. Inheritance.
D. None.

16  The relationship between an interface and the class that implements it is

A. Association
B. Aggregation
C. Inheritance
D. None

Section 12.6 Case Study: The Rational Class
17  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();

18  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 12.7 Class Design Guidelines
19  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.
D. The constructors may be protected.

20  Which of the following statements are true?

A. Override the methods equals and toString defined in the Object class whenever possible.
B. Override the hashCode method whenever the equals method is overridden. By contract, two equal objects must have the same hash code.
C. A public default no-arg constructor is assumed if no constructors are defined explicitly.
D. You should follow standard Java programming style and naming conventions. Choose informative names for classes, data fields, and methods.

21  Which of the following is poor design?

A. A data field is derived from other data fields in the same class.
B. A method must be invoked after/before invoking another method in the same class.
C. A method is an instance method, but it does not reference any instance data fields or invoke instance methods.
D. A parameter is passed from a constructor to initialize a static data field.

22  Which of the following is incorrect?

A. A constructor may be static.
B. A constructor may be private.
C. A constructor may invoke a static method.
D. A constructor may invoke an overloaded constructor.
E. A constructor invokes its superclass no-arg constructor by default if a constructor does not invoke an overloaded constructor or its superclass?s constructor.

23  Which of the following is incorrect?
A. An abstract class contains constructors.
B. The constructors in an abstract class should be protected.
C. The constructors in an abstract class are private.
D. You may declare a final abstract class.
E. An interface may contain constructors.