Deck 17: Generics

Full screen (f)
exit full mode
Question
Suppose that Point< T > is a generic type,and that we have a method of the form
Void printPoint(Point< ? > p){
// Code not shown
}

A) We will get a compiler error unless we declare the method abstract
B) We may pass any object as an actual parameter for p
C) We may only only pass Number objects as parameters for p
D) None of the above
Use Space or
up arrow
down arrow
to flip the card.
Question
The generic method
Public static < E extends Number >
Void displayArray(E[] array){
For (E element : array)System.out.println(element);
}
Can be passed

A) an array whose element type is Object
B) an array whose element type is E
C) an array whose element type is any superclass of Number
D) an array whose element type is Integer
Question
In the notation < T extends Number >,the Number class

A) specifies an upper bound for the parameter type T
B) specifies a lower bound for the parameter type T
C) specifies both an upper and lower bound for the type T
D) None of the above
Question
When a generic class with an unconstrained type parameter is instantiated without specifying an actual type argument,

A) the type Object is used for the unspecified type
B) the compiler generates an error
C) the computer throws a ClassCastException
D) None of the above
Question
Constraining a type parameter in a generic class

A) causes programs to compile faster
B) was added to Java in version 1.3 of the language
C) can only be used when the generic class will be used as a superclass for other classes
D) restricts the types that can be used as type arguments
Question
In a generic method,a type parameter is defined

A) inside the parentheses,along with the method's parameter variables.
B) after the method's return type,and before the method's name
C) before the method's return type
D) inside the body of the method,but before any local variables are declared
Question
A generic class

A) can only extend a class that is also generic
B) can extend generic and non-generic classes
C) can only extend a non generic class
D) cannot extend any class
Question
An advantage of using generic types is

A) lower compile-time overhead
B) increased portability of Java programs
C) increased type-safety without the need to do typecasts at run time
D) faster execution of programs that use generics
Question
The declaration
ArrayList< int > aL = new ArrayList< int >();

A) allows the programmer to create an ArrayList that holds integer types
B) compiles correctly,but causes an exception to be thrown at run time
C) causes a compile-time error
D) compiles and runs correctly,but is not recommended
Question
Let Point< T > be a generic type.We want to write a method that takes as parameter Point objects whose type parameter is the Number class,or any subclass of Number.We can do this by declaring the type of the method parameter as

A) Point< Number >
B) Point< ? super Number >
C) Point< ? extends Number >
D) Point< ? sub Number >
Question
A class is generic

A) if it is a subclass of the Object class
B) if it is a superclass of the Object class
C) if it has type parameters
D) if it has method parameters
Question
The automatic conversion of a wrapper type to the corresponding primitive type when the wrapper type is assigned to a variable of the primitive type is called

A) autoboxing
B) unboxing
C) type casting
D) autoconversion
Question
When a generic class is instantiated without specifying an actual type argument,the generic class is being used

A) to enhance the efficiency of the program
B) as a raw type
C) as an abstract class
D) as an interface
Question
Consider a method of the form
Void printPoint(Point< Number > p){
//Code not shown
}
Where Point< T > is a generic type.When the method is called,the only objects that may be passed for the parameter p are

A) Point< Number > objects only
B) Point< T > objects,where T is the Number class,or is any subclass of Number
C) Point< T > objects,where T is the Number class,or is any superclass of Number
D) All of the above
Question
One of the advantages of using generics is

A) that more type problems can be uncovered at compile-time rather than at run time
B) that programs that use generics are smaller when translated to byte code
C) that program that use generics execute faster than programs that do not
D) that programs that use generic code require less effort in design and development
Question
The automatic conversion of a primitive type to the corresponding wrapper type when being passed as parameter to a generic class is called

A) type promotion
B) type wrapping
C) autoconversion
D) autoboxing
Question
Look at the following method header:
Void displayPoint(Point< ? extends Number > myPoint)Which of the following objects can be passed as an argument to the displayPoint method?

A) Point< Number > p;
B) Point< Integer > p;
C) Point < Double > p;
D) All of the above
Question
When you create an instance of a generic class,what types can you pass as arguments for the class type parameters?

A) primitive types only
B) reference types only
C) interface types only
D) primitive,reference,and interface types
Question
The Java notation MyClass< Student > means that

A) the contents of Student are greater than the contents of MyClass
B) the contents of Student are included in the contents of each MyClass object
C) MyClass is a generic class
D) MyClass is a subclass of Student
Question
Look at the following method header:
Void displayPoint(Point< ? super Double > myPoint)Which of the following objects can be passed as an argument to the displayPoint method?

A) Point< Number > p;
B) Point< Object > p;
C) Point< Double > p;
D) All of the above
Question
The code fragment
Class MySArrayList extends ArrayList< String >
{
}

A) is a correct way to extend a class
B) is incorrect because there is no type variable
C) is incorrect because it is missing the wildcard symbol
D) None of the above
Question
Erasure is the process of

A) removing references to generic interfaces during execution
B) returning the null value when the compiler cannot determine the value of a generic reference
C) replacing generic types with their upper bound,or with Object,during compilation
D) deleting generic types that cannot be correctly resolved during compilation
Question
When a generic method is called,

A) the programmer must explicitly specify the actual types to use for the type parameters
B) the compiler determines the actual types to use for the type parameters from the context
C) the compiler uses information explicitly specified by the programmer,if available;otherwise,the type defaults to Object
D) None of the above
Question
A reference to a subclass object can be assigned to a superclass variable

A) only if neither the subclass nor the superclass is generic
B) only if at most one of the subclass and superclass is generic
C) only if the subclass is not generic
D) with no restrictions on the genericity of the subclass or superclass
Question
A type parameter can be constrained

A) with an upper bound and a lower bound,but not at the same time
B) with both an upper and a lower bound at the same time
C) with an upper bound only
D) with a lower bound only
Question
The notation < E implements Comparable< E > >

A) will be rejected by the Compiler as an error
B) declares a generic type that implements the Comparable interface
C) is used when there is a recursive definition of the generic type E
D) None of the above
Question
Exceptions of a generic type

A) may have at most a single type parameter
B) may have an unlimited number of type parameters
C) have very high execution overhead
D) are not permitted in Java
Question
The notation < E extends Comparable< E > >

A) will be rejected by the Compiler as an error
B) declares a generic type that implements the Comparable interface
C) is used when there is a recursive definition of the generic type E
D) None of the above
Question
Let Point< T > be a generic type.We want to write a method that takes as parameter Point objects whose type parameter is the Number class,or any superclass of Number.We can do this by writing

A) Point< Number >
B) Point< ? super Number >
C) Point< ? extends Number >
D) Point< ? sub Number >
Question
Which of the following statements are true?

A) The compiler translates generic code by replacing generic types with Object,or with the upper bounds of those types.
B) The compiler often has to insert type casts into code that results from translating generic ode
C) Generic types do not exist at the byte code level
D) All of the above
Question
Which of the following statements is true?

A) Generic types do not exist at the byte code level.
B) A raw type is a class that cannot be extended.
C) A raw type is a class that must be extended to be used.
D) A generic class cannot be abstract.
Question
Which of the following statements is true?

A) Interfaces may not be generic in Java
B) The keyword implements cannot be used do describe a type parameter that implements an interface
C) a generic class may not have more than one type parameter in its declaration
D) None of the above statements are true.
Question
The declaration
Class Point< T extends Number >
{
}
Is an example of

A) a generic class extending the class Number
B) a generic class extending a non-generic class
C) a generic class extending another generic class
D) a non-generic class extending a generic class
Question
The process used by the Java compiler to remove generic notation and substitute actual type arguments for formal type parameters is called

A) erasure
B) removal
C) substitution
D) masking
Question
Comparable< T > is

A) a generic class that you can to instantiate objects that can be compared
B) is a method defined in the Java class libraries that is used to compare objects of generic type
C) is a library module that is useful in implementing generics
D) is an interface defined in the Java class libraries
Question
Which of the following statements is true?

A) The CompareTo method is implemented by the String class
B) The CompareTo method is implemented by all the subclasses of the Number class
C) The Comparable interface is defined in the Java class libraries
D) All of the above statements are true.
Question
The process of erasure

A) helps generic code coexist with older code written in pre 1.5 versions of Java
B) removes generic classes that are never instantiated from the program
C) removes generic classes that are never instantiated,and generic methods that are never called,from the program
D) deletes generic code that is found to be inefficient
Question
In the notation < T super Number > the Number class

A) specifies an upper bound for the parameter type T
B) specifies a lower bound for the parameter type T
C) specifies both an upper and lower bound for the type T
D) None of the above
Question
The class
Public class Point3D< T extends Number > extends Point< T > {
}
Is an example of

A) a generic class extending the class Number
B) a generic class extending a non-generic class
C) a generic class extending another generic class
D) a non-generic class extending a generic class
Question
Which of the following generic type notations uses a wildcard?

A) Point< W >
B) Point< T extends Number >
C) Point< T super Integer >
D) Point< ? >
Question
The clause
Catch(Exception< T > e){
}

A) can be used to catch exceptions that are parameterized by type
B) compiles correctly,but is best avoided because of a high runtime overhead
C) compiles correctly,but may throw a ClassCastException of the wrong type is passed
D) None of the above
Question
Consider the class
Class Value < T extends Number >
{
Private T v;
Public Value(T v1){
V = v1;
}
Public void output(){
System.out.println(v);
}
}
The code
Value< Double > nV1 = new Value< Double >(34.5);

A) will cause a compiler error
B) will compile correctly,but cause an exception at run time
C) will compile and run correctly
D) None of the above
Question
A static field of a generic class

A) can only be referenced by a generic static method
B) may not have as its type one of the type parameters of the class
C) may have any type that is legal in Java
D) None of the above
Question
The code
Public class MyClass< T >
{
Public MyClass(){
T myObject = new T();
}
}

A) will not compile
B) compiles correctly,but causes a runtime exception when the program is executed
C) compiles and runs correctly,but is inefficient
D) compiles and runs correctly and efficiently
Question
Consider the class
Class Value < T extends Number >
{
Private T v;
Public Value(T v1){
V = v1;
}
Public void output(){
System.out.println(v);
}
}
The code
Value< Number > nV1 = new Value< Double >(34.5);

A) will cause a compiler error
B) will compile correctly,but cause an exception at run time
C) will compile and run correctly
D) None of the above
Question
The code
ArrayList< String > [ ] a = new ArrayList< String >[100];

A) will not compile
B) compiles correctly,but causes a runtime exception when the program is executed
C) compiles and runs correctly,but is inefficient
D) compiles and runs correctly and efficiently
Question
A static method of a generic class

A) can refer to any of the type parameters of its class
B) cannot refer to any of the type parameters of its class
C) must specify an upper bound for its type parameters
D) None of the above
Question
A generic class

A) may create instances of any of its type parameters
B) may not create instances of any of its type parameters
C) may not implement interfaces that are generic
D) None of the above
Question
Which of the following statements are true?

A) You cannot instantiate an object of a generic type
B) You cannot create arrays whose elements are instances of a generic type
C) You can declare references to arrays whose elements are of a generic type
D) All of the above
Question
Consider the class
Class Value < T extends Number >
{
Private T v;
Public Value(T v1){
V = v1;
}
Public void output(){
System.out.println(v);
}
}
The code
Value< Number > nV = new Value< Number >(12);

A) will cause a compiler error
B) will compile correctly,but cause an exception at run time
C) will compile and run correctly
D) None of the above
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/50
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 17: Generics
1
Suppose that Point< T > is a generic type,and that we have a method of the form
Void printPoint(Point< ? > p){
// Code not shown
}

A) We will get a compiler error unless we declare the method abstract
B) We may pass any object as an actual parameter for p
C) We may only only pass Number objects as parameters for p
D) None of the above
D
2
The generic method
Public static < E extends Number >
Void displayArray(E[] array){
For (E element : array)System.out.println(element);
}
Can be passed

A) an array whose element type is Object
B) an array whose element type is E
C) an array whose element type is any superclass of Number
D) an array whose element type is Integer
D
3
In the notation < T extends Number >,the Number class

A) specifies an upper bound for the parameter type T
B) specifies a lower bound for the parameter type T
C) specifies both an upper and lower bound for the type T
D) None of the above
A
4
When a generic class with an unconstrained type parameter is instantiated without specifying an actual type argument,

A) the type Object is used for the unspecified type
B) the compiler generates an error
C) the computer throws a ClassCastException
D) None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
5
Constraining a type parameter in a generic class

A) causes programs to compile faster
B) was added to Java in version 1.3 of the language
C) can only be used when the generic class will be used as a superclass for other classes
D) restricts the types that can be used as type arguments
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
6
In a generic method,a type parameter is defined

A) inside the parentheses,along with the method's parameter variables.
B) after the method's return type,and before the method's name
C) before the method's return type
D) inside the body of the method,but before any local variables are declared
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
7
A generic class

A) can only extend a class that is also generic
B) can extend generic and non-generic classes
C) can only extend a non generic class
D) cannot extend any class
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
8
An advantage of using generic types is

A) lower compile-time overhead
B) increased portability of Java programs
C) increased type-safety without the need to do typecasts at run time
D) faster execution of programs that use generics
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
9
The declaration
ArrayList< int > aL = new ArrayList< int >();

A) allows the programmer to create an ArrayList that holds integer types
B) compiles correctly,but causes an exception to be thrown at run time
C) causes a compile-time error
D) compiles and runs correctly,but is not recommended
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
10
Let Point< T > be a generic type.We want to write a method that takes as parameter Point objects whose type parameter is the Number class,or any subclass of Number.We can do this by declaring the type of the method parameter as

A) Point< Number >
B) Point< ? super Number >
C) Point< ? extends Number >
D) Point< ? sub Number >
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
11
A class is generic

A) if it is a subclass of the Object class
B) if it is a superclass of the Object class
C) if it has type parameters
D) if it has method parameters
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
12
The automatic conversion of a wrapper type to the corresponding primitive type when the wrapper type is assigned to a variable of the primitive type is called

A) autoboxing
B) unboxing
C) type casting
D) autoconversion
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
13
When a generic class is instantiated without specifying an actual type argument,the generic class is being used

A) to enhance the efficiency of the program
B) as a raw type
C) as an abstract class
D) as an interface
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
14
Consider a method of the form
Void printPoint(Point< Number > p){
//Code not shown
}
Where Point< T > is a generic type.When the method is called,the only objects that may be passed for the parameter p are

A) Point< Number > objects only
B) Point< T > objects,where T is the Number class,or is any subclass of Number
C) Point< T > objects,where T is the Number class,or is any superclass of Number
D) All of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
15
One of the advantages of using generics is

A) that more type problems can be uncovered at compile-time rather than at run time
B) that programs that use generics are smaller when translated to byte code
C) that program that use generics execute faster than programs that do not
D) that programs that use generic code require less effort in design and development
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
16
The automatic conversion of a primitive type to the corresponding wrapper type when being passed as parameter to a generic class is called

A) type promotion
B) type wrapping
C) autoconversion
D) autoboxing
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
17
Look at the following method header:
Void displayPoint(Point< ? extends Number > myPoint)Which of the following objects can be passed as an argument to the displayPoint method?

A) Point< Number > p;
B) Point< Integer > p;
C) Point < Double > p;
D) All of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
18
When you create an instance of a generic class,what types can you pass as arguments for the class type parameters?

A) primitive types only
B) reference types only
C) interface types only
D) primitive,reference,and interface types
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
19
The Java notation MyClass< Student > means that

A) the contents of Student are greater than the contents of MyClass
B) the contents of Student are included in the contents of each MyClass object
C) MyClass is a generic class
D) MyClass is a subclass of Student
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
20
Look at the following method header:
Void displayPoint(Point< ? super Double > myPoint)Which of the following objects can be passed as an argument to the displayPoint method?

A) Point< Number > p;
B) Point< Object > p;
C) Point< Double > p;
D) All of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
21
The code fragment
Class MySArrayList extends ArrayList< String >
{
}

A) is a correct way to extend a class
B) is incorrect because there is no type variable
C) is incorrect because it is missing the wildcard symbol
D) None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
22
Erasure is the process of

A) removing references to generic interfaces during execution
B) returning the null value when the compiler cannot determine the value of a generic reference
C) replacing generic types with their upper bound,or with Object,during compilation
D) deleting generic types that cannot be correctly resolved during compilation
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
23
When a generic method is called,

A) the programmer must explicitly specify the actual types to use for the type parameters
B) the compiler determines the actual types to use for the type parameters from the context
C) the compiler uses information explicitly specified by the programmer,if available;otherwise,the type defaults to Object
D) None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
24
A reference to a subclass object can be assigned to a superclass variable

A) only if neither the subclass nor the superclass is generic
B) only if at most one of the subclass and superclass is generic
C) only if the subclass is not generic
D) with no restrictions on the genericity of the subclass or superclass
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
25
A type parameter can be constrained

A) with an upper bound and a lower bound,but not at the same time
B) with both an upper and a lower bound at the same time
C) with an upper bound only
D) with a lower bound only
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
26
The notation < E implements Comparable< E > >

A) will be rejected by the Compiler as an error
B) declares a generic type that implements the Comparable interface
C) is used when there is a recursive definition of the generic type E
D) None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
27
Exceptions of a generic type

A) may have at most a single type parameter
B) may have an unlimited number of type parameters
C) have very high execution overhead
D) are not permitted in Java
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
28
The notation < E extends Comparable< E > >

A) will be rejected by the Compiler as an error
B) declares a generic type that implements the Comparable interface
C) is used when there is a recursive definition of the generic type E
D) None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
29
Let Point< T > be a generic type.We want to write a method that takes as parameter Point objects whose type parameter is the Number class,or any superclass of Number.We can do this by writing

A) Point< Number >
B) Point< ? super Number >
C) Point< ? extends Number >
D) Point< ? sub Number >
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
30
Which of the following statements are true?

A) The compiler translates generic code by replacing generic types with Object,or with the upper bounds of those types.
B) The compiler often has to insert type casts into code that results from translating generic ode
C) Generic types do not exist at the byte code level
D) All of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
31
Which of the following statements is true?

A) Generic types do not exist at the byte code level.
B) A raw type is a class that cannot be extended.
C) A raw type is a class that must be extended to be used.
D) A generic class cannot be abstract.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
32
Which of the following statements is true?

A) Interfaces may not be generic in Java
B) The keyword implements cannot be used do describe a type parameter that implements an interface
C) a generic class may not have more than one type parameter in its declaration
D) None of the above statements are true.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
33
The declaration
Class Point< T extends Number >
{
}
Is an example of

A) a generic class extending the class Number
B) a generic class extending a non-generic class
C) a generic class extending another generic class
D) a non-generic class extending a generic class
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
34
The process used by the Java compiler to remove generic notation and substitute actual type arguments for formal type parameters is called

A) erasure
B) removal
C) substitution
D) masking
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
35
Comparable< T > is

A) a generic class that you can to instantiate objects that can be compared
B) is a method defined in the Java class libraries that is used to compare objects of generic type
C) is a library module that is useful in implementing generics
D) is an interface defined in the Java class libraries
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
36
Which of the following statements is true?

A) The CompareTo method is implemented by the String class
B) The CompareTo method is implemented by all the subclasses of the Number class
C) The Comparable interface is defined in the Java class libraries
D) All of the above statements are true.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
37
The process of erasure

A) helps generic code coexist with older code written in pre 1.5 versions of Java
B) removes generic classes that are never instantiated from the program
C) removes generic classes that are never instantiated,and generic methods that are never called,from the program
D) deletes generic code that is found to be inefficient
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
38
In the notation < T super Number > the Number class

A) specifies an upper bound for the parameter type T
B) specifies a lower bound for the parameter type T
C) specifies both an upper and lower bound for the type T
D) None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
39
The class
Public class Point3D< T extends Number > extends Point< T > {
}
Is an example of

A) a generic class extending the class Number
B) a generic class extending a non-generic class
C) a generic class extending another generic class
D) a non-generic class extending a generic class
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
40
Which of the following generic type notations uses a wildcard?

A) Point< W >
B) Point< T extends Number >
C) Point< T super Integer >
D) Point< ? >
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
41
The clause
Catch(Exception< T > e){
}

A) can be used to catch exceptions that are parameterized by type
B) compiles correctly,but is best avoided because of a high runtime overhead
C) compiles correctly,but may throw a ClassCastException of the wrong type is passed
D) None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
42
Consider the class
Class Value < T extends Number >
{
Private T v;
Public Value(T v1){
V = v1;
}
Public void output(){
System.out.println(v);
}
}
The code
Value< Double > nV1 = new Value< Double >(34.5);

A) will cause a compiler error
B) will compile correctly,but cause an exception at run time
C) will compile and run correctly
D) None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
43
A static field of a generic class

A) can only be referenced by a generic static method
B) may not have as its type one of the type parameters of the class
C) may have any type that is legal in Java
D) None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
44
The code
Public class MyClass< T >
{
Public MyClass(){
T myObject = new T();
}
}

A) will not compile
B) compiles correctly,but causes a runtime exception when the program is executed
C) compiles and runs correctly,but is inefficient
D) compiles and runs correctly and efficiently
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
45
Consider the class
Class Value < T extends Number >
{
Private T v;
Public Value(T v1){
V = v1;
}
Public void output(){
System.out.println(v);
}
}
The code
Value< Number > nV1 = new Value< Double >(34.5);

A) will cause a compiler error
B) will compile correctly,but cause an exception at run time
C) will compile and run correctly
D) None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
46
The code
ArrayList< String > [ ] a = new ArrayList< String >[100];

A) will not compile
B) compiles correctly,but causes a runtime exception when the program is executed
C) compiles and runs correctly,but is inefficient
D) compiles and runs correctly and efficiently
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
47
A static method of a generic class

A) can refer to any of the type parameters of its class
B) cannot refer to any of the type parameters of its class
C) must specify an upper bound for its type parameters
D) None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
48
A generic class

A) may create instances of any of its type parameters
B) may not create instances of any of its type parameters
C) may not implement interfaces that are generic
D) None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
49
Which of the following statements are true?

A) You cannot instantiate an object of a generic type
B) You cannot create arrays whose elements are instances of a generic type
C) You can declare references to arrays whose elements are of a generic type
D) All of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
50
Consider the class
Class Value < T extends Number >
{
Private T v;
Public Value(T v1){
V = v1;
}
Public void output(){
System.out.println(v);
}
}
The code
Value< Number > nV = new Value< Number >(12);

A) will cause a compiler error
B) will compile correctly,but cause an exception at run time
C) will compile and run correctly
D) None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 50 flashcards in this deck.