Introduction to Java Programming, Sixth Edition, Y. Daniel Liang
Chapter 11 Object-Oriented Modeling
Section 11.2 Software development process
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 11.3 Discovering Class Relationships
3
_________ is a general binary relationship that describes an activity between two objects.
A.
Association
B.
Aggregation
C.
Composition
D.
Inheritance
4
__________ is a special form of association that represents an ownership relationship between two objects.
A.
Association
B.
Aggregation
C.
Composition
D.
Inheritance
5
__________ represents an exclusive ownership relationship between two objects.
A.
Association
B.
Aggregation
C.
Composition
D.
Inheritance
6
__________ models the is-a relationship between two classes.
A.
Association
B.
Aggregation
C.
Composition
D.
Inheritance
7
___________ 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
8
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
9
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.
10
What is the best suitable relationship between Company and Employee?
A.
Association
B.
Aggregation
C.
Inheritance
D.
None
11
A faculty teaches a course. What is the best suitable relationship between Faculty and Course?
A.
Association
B.
Aggregation
C.
Inheritance
D.
None
12
What is the best suitable relationship between Employee and Faculty?
A.
Association.
B.
Aggregation.
C.
Inheritance.
D.
None.
13
The relationship between an interface and the class that implements it is
A.
Association
B.
Aggregation
C.
Inheritance
D.
None
Section 11.5 The Rational Class
14
The Rational class in this chapter is defined as a subclass of java.lang.Number. Which of the following expression 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();
15
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 syntax 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 syntax 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 11.6 Class Design Guidelines
16
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.
17
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.
Section 11.7 Modeling Dynamic Behavior Using Sequence Diagrams and Statecharts
18
__________ describe interactions among objects by depicting the time-ordering of method invocations.
A.
Sequence diagrams
B.
Statechart diagrams
C.
Flowchart diagrams
D.
Class diagrams
19
__________ represents the roles the object plays. The objects at the top of the diagram represent class roles.
A.
Class role
B.
Lifeline
C.
Activation
D.
Method invocation
20
__________ describe the flow of control of an object.
A.
Sequence diagrams
B.
Statechart diagrams
C.
Flowchart diagrams
D.
Class diagrams
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.