Deck 20: Generic Classes and Methods: a Deeper Look

Full screen (f)
exit full mode
Question
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.
Use Space or
up arrow
down arrow
to flip the card.
Question
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.
Question
Which of the following statements is false?

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.
Question
Class Number is ________ of both Integer and Double.

A) the subclass
B) composed
C) a descendent
D) the superclass
Question
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.
Question
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.
Question
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.
Question
__________ 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.
Question
A wildcard type argument is denoted by a(n) __________.

A) asterisk (*).
B) underscore (_).
C) question mark (?).
D) caret (^).
Question
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.
Question
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.
Question
One generic Stack class could be the basis for creating many Stack classes,g., Stack<Double>, Stack<Integer> and Stack<Employee>. These classes are known as __________.

A) subclasses.
B) generic subclasses.
C) concrete classes.
D) parameterized classes.
Question
__________ is the default upper bound of a type parameter.

A) String.
B) Comparable.
C) Class.
D) Object.
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/13
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 20: Generic Classes and Methods: a Deeper Look
1
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.
A
2
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.
angle brackets (< and >).
3
Which of the following statements is false?

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.
Because a wildcard is a type-parameter name, you can use it as a type name throughout a method's body.
4
Class Number is ________ of both Integer and Double.

A) the subclass
B) composed
C) a descendent
D) the superclass
Unlock Deck
Unlock for access to all 13 flashcards in this deck.
Unlock Deck
k this deck
5
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.
Unlock Deck
Unlock for access to all 13 flashcards in this deck.
Unlock Deck
k this deck
6
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.
Unlock Deck
Unlock for access to all 13 flashcards in this deck.
Unlock Deck
k this deck
7
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.
Unlock Deck
Unlock for access to all 13 flashcards in this deck.
Unlock Deck
k this deck
8
__________ 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.
Unlock Deck
Unlock for access to all 13 flashcards in this deck.
Unlock Deck
k this deck
9
A wildcard type argument is denoted by a(n) __________.

A) asterisk (*).
B) underscore (_).
C) question mark (?).
D) caret (^).
Unlock Deck
Unlock for access to all 13 flashcards in this deck.
Unlock Deck
k this deck
10
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.
Unlock Deck
Unlock for access to all 13 flashcards in this deck.
Unlock Deck
k this deck
11
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.
Unlock Deck
Unlock for access to all 13 flashcards in this deck.
Unlock Deck
k this deck
12
One generic Stack class could be the basis for creating many Stack classes,g., Stack<Double>, Stack<Integer> and Stack<Employee>. These classes are known as __________.

A) subclasses.
B) generic subclasses.
C) concrete classes.
D) parameterized classes.
Unlock Deck
Unlock for access to all 13 flashcards in this deck.
Unlock Deck
k this deck
13
__________ is the default upper bound of a type parameter.

A) String.
B) Comparable.
C) Class.
D) Object.
Unlock Deck
Unlock for access to all 13 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 13 flashcards in this deck.