Java How to Program, 11/e Multiple Choice Test Bank 1 of 3
Chapter 20 Generic Classes and Methods
Section 20.1 Introduction
20.1 Q1: __________ enable programmers to specify, with a single method declaration, a set of related
methods.
a. Overloaded methods.
b. Overriden methods.
c. Generic methods.
d. Generics.
20.1 Q2: Generics provide __________ that allows programmers to catch invalid types at compile time.
a. compile-time type safety.
b. compile-time exception handling.
c. compile-time error checking.
d. run-time type safety.
Section 20.2 Motivation for Generic Methods
20.2 Q1: Which of the following statements is true?
a. Overloaded methods are often used to perform similar operations on different types of data.
b. When the compiler encounters a method call, it attempts to locate a method declaration with a name and
parameters that are compatible with the argument types in the method call.
c. Both a) and b) are true.
d. Neither a) nor b) is true.
Section 20.3 Generic Methods: Implementation and Compile–
Time Translation
20.3 Q1: All generic method declarations have a type parameter section delimited by __________.
a. curly brackets ({ and }).
b. angle brackets (< and >).
c. square brackets ([ and ] ).
d. parenthesis.
20.3 Q2: Which statement is false?
a. When declaring a generic method, the type parameter section is placed before the return type of the
method.
b. Each type parameter section contains only one type parameter.
c. A type parameter is an identifier that specifies a generic type name.
d. Type parameters can represent only reference types.
Section 20.4 Additional Compile-Time Translation Issues:
Methods That Use a Type Parameter as the Return Type
20.4 Q1: __________ is the default upper bound of a type parameter.
a. String.
Java How to Program, 11/e Multiple Choice Test Bank 2 of 3
b. Comparable.
c. Class.
d. Object.
20.4 Q2: When the compiler translates a generic method into Java bytecodes, it uses __________ to replace
the type parameters with actual types.
a. erasure.
b. compile-time type replacement.
c. compile-time type checking.
d. compile-time type safety.
Section 20.5 Overloading Generic Methods
20.5 Q1: Which statement is false?
a. A generic method may be overloaded.
b. A class can provide two or more generic methods that specify the same method name but different
method parameters.
c. A generic method cannot be overloaded by non-generic methods.
d. When the compiler encounters a method call, it searches for the method declaration that most precisely
matches the method name and the argument types specified in the call.
Section 20.6 Generic Classes
20.6 Q1: One generic Stack class could be the basis for creating many Stack classes, e.g., Stack<Double>,
Stack<Integer> and Stack<Employee>. These classes are known as __________.
a. subclasses.
b. generic subclasses.
c. concrete classes.
d. parameterized classes.
20.6 Q2: When compiling a generic class, the __________ option should be used to view the unchecked
warning message.
a. -Xlint:unchecked.
b. -X:unchecked.
c. -warning:unchecked.
d. -unchecked.
Section 20.7 Wildcards in Methods That Accept Type Parameters
20.8 Q1: Class Number is ________ of both Integer and Double.
a. the subclass
b. composed
c. a descendent
d. the superclass
20.8 Q2:Which of the following statements is false?
Java How to Program, 11/e Multiple Choice Test Bank 3 of 3
a. Wildcard type arguments enable you to specify method parameters, return values, variables, and so on,
that act as supertypes of parameterized types.
b. A wildcard-type argument is denoted by ?, which represents an “unknown type.”
c. Because a wildcard is a type-parameter name, you can use it as a type name throughout a method’s body.
d. If a wildcard is specified without an upper bound, then only the methods of type Object can be invoked
on values of the wildcard type.
20.8 Q3: A wildcard type argument is denoted by a(n) __________.
a. asterisk (*).
b. underscore (_).
c. question mark (?).
d. caret (^).