Exam 18: Generic Classes

arrow
  • Select Tags
search iconSearch Question
flashcardsStudy Flashcards
  • Select Tags

What does it mean when the syntax ? extends D is used?

(Multiple Choice)
4.8/5
(38)

Consider the following code snippet: Public class SavingsAccount extends BankAccount { . . . } Public class CheckingAccount extends BankAccount { . . . } ) . . SavingsAccount[] savingsAccounts = new SavingsAccount[100]; //Line 1 BankAccount bankAccounts = savingsAccounts; //Line 2 BankAccount myAccount = new CheckingAccount(); //Line 3 BankAccounts[0] = myAccount; //Line 4 Which of the following statements regarding this code is correct?

(Multiple Choice)
4.9/5
(37)

What is the result when a program constructs a generic class without passing a type variable, as in the following code? Stack stack = new Stack(); I the program will compile and run II the compiler will issue an error III the compiler will issue a warning

(Multiple Choice)
4.7/5
(35)

Consider the following code snippet: Public class Box<E> { Private E data; Public Box(){ . . . } Public void insert(E value) { . . . } Public E getData(){ . . . } } What will result from executing the following code? Box<String> box = new Box<String>(); ) . . Box)insert("blue Box"); String b = (Object) box.getData();

(Multiple Choice)
4.8/5
(41)

Consider the following code snippet: Public static void reverse(List<?> list) { . . . } This method declaration is equivalent to which of the following declarations?

(Multiple Choice)
4.9/5
(42)

Consider the following code snippet: Public static <T> void fun(T[] t) { . . . } Erasure by the compiler of method fun will generate which result?

(Multiple Choice)
4.8/5
(33)

Which code is the equivalent of the following method header? Public static <E> void abc(Stack<E> stack) { . . . } I public static void abc(Stack<?> stack) { . . . } II public static <Object> void abc (Stack<Object> stack) { . . . } III public static void abc(Stack stack) { . . . }

(Multiple Choice)
4.9/5
(39)

Consider the following code snippet: Public interface MyInterface<E> { . . . } Public interface YourInterface<E, T> extends MyInterface<E> { . . . } Which of these are legal class declarations? I public class SomeClass implements YourInterface<String, Double> { . . . } II public class SomeClass implements YourInterface { . . . } III public class SomeClass implements YourInterface<String> { . . . }

(Multiple Choice)
5.0/5
(40)

Consider the following code snippet: Public class Box<E> { Private E data; Public Box() { . . . } } Which of the following choices is a specific type of the generic Box class?

(Multiple Choice)
4.9/5
(29)

Which of the following satisfies the wildcard ? super Object?

(Multiple Choice)
4.9/5
(36)

Which of the following are restrictions of Java generic programming? I You cannot use the assignment operator = to assign one generic object to another. II You cannot use the == operator to compare two generic objects. III You cannot construct arrays of generic types.

(Multiple Choice)
4.8/5
(36)

Which Java technique(s) allows generic programming? I type variables II primitive types III inheritance

(Multiple Choice)
4.8/5
(42)

Which of the following statements about generic programming is NOT correct?

(Multiple Choice)
4.8/5
(29)

Which of the following statements about generic methods is correct?

(Multiple Choice)
4.8/5
(37)

Which of the following statements about generic programming is NOT correct?

(Multiple Choice)
4.8/5
(42)

What is the best technique for overcoming the restriction for the use of primitives, such as int, in generic classes and methods?

(Multiple Choice)
4.8/5
(34)

Which of the following headers for a generic method myMethod allows the actionPerformed method from the ActionListener class to be called? I public static <E extends ActionListener> E myMethod(E e) II public static <E implements ActionListener> E myMethod(E e) III public <E extends ActionListener> E myMethod(E e)

(Multiple Choice)
4.8/5
(36)

What does it mean when the syntax ? super D is used?

(Multiple Choice)
4.8/5
(39)

Suppose a generic method accepts a generic unconstrained argument p. What restrictions are placed on p by the compiler?

(Multiple Choice)
4.9/5
(40)

Which of the following statements about the Java virtual machine is correct?

(Multiple Choice)
4.8/5
(42)
Showing 21 - 40 of 78
close modal

Filters

  • Essay(0)
  • Multiple Choice(0)
  • Short Answer(0)
  • True False(0)
  • Matching(0)