Deck 21: Generic Classes and Methods
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/13
Play
Full screen (f)
Deck 21: Generic Classes and Methods
1
Which statement is false?
A)A generic class can be derived from a non-generic class.
B)A non-generic class cannot be derived from a generic class.
C)A generic class can be derived from another generic class.
D)A generic method in a subclass can override a generic method in a superclass if both methods have the same signatures.
A)A generic class can be derived from a non-generic class.
B)A non-generic class cannot be derived from a generic class.
C)A generic class can be derived from another generic class.
D)A generic method in a subclass can override a generic method in a superclass if both methods have the same signatures.
B
2
Which statement is false?
A)Parameterized type ArrayList< Number > is a supertype of ArrayList< Integer >.
B)ArrayList implements a dynamically resizable,array-like data structure.
C)A wildcard represents an "unknown type".
D)Because the wildcard in a method's header does not specify a type parameter name,you cannot use it as a type name throughout the method's body.
A)Parameterized type ArrayList< Number > is a supertype of ArrayList< Integer >.
B)ArrayList implements a dynamically resizable,array-like data structure.
C)A wildcard represents an "unknown type".
D)Because the wildcard in a method's header does not specify a type parameter name,you cannot use it as a type name throughout the method's body.
A
3
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.
A)erasure.
B)compile-time type replacement.
C)compile-time type checking.
D)compile-time type safety.
A
4
Suppose Stack is a generic class that has one type parameter.The following assignment Stack< Integer > integerStack = new Stack( 10 );
Is __________.
A)illegal.
B)permitted and safe.
C)permitted but unsafe,the compiler issues a warning message.
D)permitted but unsafe,the runtime environment issues a warning message.
Is __________.
A)illegal.
B)permitted and safe.
C)permitted but unsafe,the compiler issues a warning message.
D)permitted but unsafe,the runtime environment issues a warning message.
Unlock Deck
Unlock for access to all 13 flashcards in this deck.
Unlock Deck
k this deck
5
A wildcard type argument is denoted by a(n)__________.
A)asterisk (*).
B)underscore (_).
C)question mark (?).
D)caret (^).
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
6
__________ is the default upper bound of a type parameter.
A)String.
B)Comparable.
C)Class.
D)Object.
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
7
__________ 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.
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
8
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.
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
9
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.
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
10
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.
A)curly brackets ({ and }).
B)angle brackets (< and >).
C)square brackets ([ and ] ).
D)parenthesis.
Unlock Deck
Unlock for access to all 13 flashcards in this deck.
Unlock Deck
k this deck
11
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)compile-time type safety.
B)compile-time exception handling.
C)compile-time error checking.
D)run-time type safety.
Unlock Deck
Unlock for access to all 13 flashcards in this deck.
Unlock Deck
k this deck
12
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.
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
13
When a generic class is instantiated without specifying a type argument,it is said to have a __________.
A)empty type.
B)raw type.
C)null type.
D)abstract type.
A)empty type.
B)raw type.
C)null type.
D)abstract type.
Unlock Deck
Unlock for access to all 13 flashcards in this deck.
Unlock Deck
k this deck