Exam 18: Generic Classes

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

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?

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

C

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

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

D

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 compile-time error?

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

C

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)

If a class requires two generic type variables, how many can you legally provide in Java? I 0 II 1 III 2

(Multiple Choice)
4.9/5
(41)

Which Java generic programming technique(s) requires the programmer to use casting to access variables stored as Object types? I type variables II primitive types III inheritance

(Multiple Choice)
4.9/5
(33)

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?

(Multiple Choice)
4.9/5
(41)

Consider the following declaration: LinkedList<String> list = new LinkedList<String>(); This declaration implies that the LinkedList class could begin with which of the following code statements? I public class LinkedList<String> { . . . } II public class LinkedList<S> { . . . } III public class LinkedList<Element> { . . . }

(Multiple Choice)
4.7/5
(28)

Consider the following code snippet: Public static <E extends Measurable> E min(E[] objects) Which of the following represents the result of type erasure on this code?

(Multiple Choice)
4.9/5
(34)

In Java, generic programming can be achieved with ____.

(Multiple Choice)
4.9/5
(40)

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

(Multiple Choice)
4.9/5
(37)

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");

(Multiple Choice)
4.8/5
(31)

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

Consider the following code snippet: Public class Box<E> { Private E data; Public Box(){ . . . } Public void insert(E value) { . . . } } Which of the following is a valid Box<E> object instantiation? I Box<Object> box = new Box<Object>(); II Box<Boolean> box = new Box<Boolean>(); III Box<double> box = new Box<double>();

(Multiple Choice)
4.9/5
(52)

Consider the following code snippet: Public class Box<E> { Private E data; Public Box(){ . . . } Public void insert(E value) { . . . } Public E getData(){ . . . } } What specific exception will be thrown when the following code executes? Box<String> box = new Box<String>(); ) . . Box)insert("blue Box"); Double myDouble = (Double) box.getData();

(Multiple Choice)
4.9/5
(36)

Which of the following statements regarding restrictions for generic methods are true? I Generic methods must be declared inside a generic class. II Generic methods must be static. III Generic methods may only have one generic parameter.

(Multiple Choice)
4.8/5
(36)

Consider the following code snippet: Public class Box<E> { Private E data; Public Box(){ . . . } } Which of the following is a valid Box<E> object instantiation?

(Multiple Choice)
4.8/5
(42)

Consider the following code snippet: Public static <E> void print(E[] a) { For (int i = 0; i < a.length; i++) { System.out.println(a[i] + " "); } } Int[] a = {3,6,5,7,8,9,2,3}; Print(makeArray(a)); Assume that the method call to print(makeArray(a)) works correctly by printing the int array a. Which of the following headers for the makeArray method will make this possible? I public static Integer[] makeArray(int[] a) II public static E[] makeArray(int[] a) III public static Integer[] makeArray(E[] a)

(Multiple Choice)
4.9/5
(38)

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

Consider the following class declaration: Public class SavingsAccount extends BankAccount { . . . } Which of the following statements about these classes is correct?

(Multiple Choice)
4.8/5
(36)
Showing 1 - 20 of 78
close modal

Filters

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