Exam 18: Generic Classes

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

Consider the following code snippet: ArrayList<Coin> coins1 = new ArrayList<Coin>(); //Line 1 LinkedList coins2 = new LinkedList(); //Line 2 Coins1.add("my penny"); //Line 3 Coins2.addFirst("my penny"); //Line 4 Which of the above lines will cause a run-time error when the object is retrieved elsewhere in the program?

Free
(Multiple Choice)
4.7/5
(39)
Correct Answer:
Verified

D

To maintain compatibility with pre-generic Java, type parameters are replaced by ordinary types called ____.

Free
(Multiple Choice)
4.9/5
(37)
Correct Answer:
Verified

B

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

Free
(Multiple Choice)
4.8/5
(38)
Correct Answer:
Verified

A

Given the following declaration, what is the type parameter in Stack<E> replaced with? private Stack<String> myStack = new Stack<String>();

(Multiple Choice)
4.7/5
(35)

Which of the following satisfies the wildcard ? extends Object? I String II JComponent III Scanner

(Multiple Choice)
4.8/5
(36)

Which of the following is not a wildcard type?

(Multiple Choice)
4.9/5
(41)

Which of the following necessitates the type erasure process? I The Java virtual machine does not work with generic types II To maintain backward compatibility to older versions of Java III Generics do not work with primitives

(Multiple Choice)
4.9/5
(29)

What is known for certain about a type parameter when a method constrains it as follows? <E extends MouseListener & MouseMotionListener>

(Multiple Choice)
4.8/5
(35)

Which is the purpose of the <E> element in the class declaration below? public class Thing<E> { Public Thing() { . . . } }

(Multiple Choice)
4.9/5
(38)

Given the following declaration, what is the type parameter in Stack<E> replaced with? private Stack myStack = new Stack();

(Multiple Choice)
4.9/5
(33)

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

(Multiple Choice)
4.7/5
(37)

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

(Multiple Choice)
4.9/5
(40)

An inner helper class, such as a TreeNode inside the generic BinaryTree class, must meet which of the following criteria? I be public II be private III be declared as generic

(Multiple Choice)
4.7/5
(39)

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<Boolean> box = new Box<Boolean>(); Box b = (Box) box.getData();

(Multiple Choice)
4.8/5
(43)

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

(Multiple Choice)
4.9/5
(33)

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.9/5
(30)

Which of the following satisfies the wildcard ? extends Component?

(Multiple Choice)
4.9/5
(38)

Consider the following code snippet in the LinkedList<E> class: public void addAll(LinkedList<? extends E> other) { ListIterator<E> iter = other.listIterator(); While (iter.hasNext()) { Add(iter.next()); } } Which of the following statements about this code is correct?

(Multiple Choice)
4.9/5
(35)

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

Which of the following satisfies the wildcard ? super Object?

(Multiple Choice)
4.9/5
(34)
Showing 1 - 20 of 75
close modal

Filters

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