Exam 18: Generic Classes

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

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 the following code? Box<String> box = new Box<String>(); ) . . Box)insert("blue Box"); Double myDouble = (Double) box.getData();

(Multiple Choice)
4.7/5
(33)

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 = (String) box.getData();

(Multiple Choice)
4.8/5
(36)

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
(41)

What does the following code snippet mean: <E extends Comparable<E> & Measurable>

(Multiple Choice)
4.8/5
(37)

Generics limit Java code somewhat. Which of the following are considered limitations of generic code? I cannot have an array of a generic type II cannot have primitive type variables III cannot construct an object of a generic type

(Multiple Choice)
4.9/5
(31)

The type variables in HashMap<K, V> in the standard library mnemonically represent ____.

(Multiple Choice)
4.9/5
(35)

Consider the following code snippet: ArrayList<BankAccount> accounts1 = new ArrayList<BankAccount>(); //Line 1 LinkedList accounts2 = new LinkedList(); //Line 2 Accounts1.add("my Salary"); //Line 3 Accounts2.addFirst("my Salary"); //Line 4 Which of the above lines will cause a compile-time error?

(Multiple Choice)
4.9/5
(34)

Determine the output of the MyLinkedList generic class code below when the main method executes. public class MyLinkedList<E> { Private MyNode first; Public MyLinkedList(E

(Multiple Choice)
4.7/5
(48)

Erasure of types limits Java code somewhat with generics. Which of the following are limitations of generic code? I cannot instantiate a type variable II cannot return a type variable III cannot pass a type variable

(Multiple Choice)
4.8/5
(32)

Consider the following code snippet: public class LinkedList<E> { Private E defaultValue; Public static List<E> replicate(E value, int n) { . . . } Private class Node { public String data; public Node next;) ) . . } What is wrong with this code?

(Multiple Choice)
4.7/5
(28)

In Java, generic programming can be achieved with ____.

(Multiple Choice)
4.8/5
(44)

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

(Multiple Choice)
4.8/5
(33)

What is known for certain about Visualizer when a method constrains its type parameter as follows? <E extends Visualizer>

(Multiple Choice)
4.8/5
(31)

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

(Multiple Choice)
4.8/5
(33)

Consider the following code snippet: public static void reverse(List list) { . . . } Which of the following statements about this code is correct?

(Multiple Choice)
4.7/5
(36)
Showing 61 - 75 of 75
close modal

Filters

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