Exam 18: Generic Classes

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

Given the following generic method, which of the following CANNOT be the return type? public static <E extends Comparable> E max(E[]A) { . . .} I String II Integer III double

(Multiple Choice)
4.9/5
(34)

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.8/5
(33)

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}; String[] s = {"happy","cat","silly","dog"}; Boolean[] b = {"true", "true", "false"}; Which of the following are correct calls to this generic print method? I print(a); II print(s); III print(b);

(Multiple Choice)
4.8/5
(44)

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

Which of the following statements about generic methods is correct?

(Multiple Choice)
5.0/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)

Which argument type cannot passed to generic methods? I Object II GUI components III primitive

(Multiple Choice)
4.9/5
(41)

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

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

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?

(Multiple Choice)
4.9/5
(42)

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.8/5
(39)

Consider the following code snippet: public static <E extends Comparable<E>> E min(ArrayList<E> objects) What can we conclude about the return type of this method?

(Multiple Choice)
4.7/5
(42)

Which of these Java library classes are implemented using type variables? I HashMap II LinkedList III ArrayList

(Multiple Choice)
4.8/5
(26)

Determine the correctness of the MyLinkedList generic class code below. public class MyLinkedList<E> { Private MyNode first; Public E getFirst() { return first.data; } Private class MyNode { Private E data; Private MyNode next; } }

(Multiple Choice)
4.7/5
(34)

Which of the following statements about generic methods is correct?

(Multiple Choice)
4.9/5
(33)

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

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)
4.9/5
(41)

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

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

Consider the following code snippet that declares the GraduateStudent class: public GraduateStudent extends Student { . . .} Which of these statements are false? I GraduateStudent is a subclass of Student II Stack<GraduateStudent> is a subclass of Stack<Student> III Stack<Student> is a subclass of Stack<GraduateStudent>

(Multiple Choice)
4.9/5
(37)
Showing 41 - 60 of 75
close modal

Filters

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