Exam 18: Generic Classes

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

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

(Multiple Choice)
4.7/5
(31)

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

(Multiple Choice)
4.8/5
(28)

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

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

Consider our own generic class MyLinkedList shown below.It has a private Node class, and it implements the standard Java ListIterator generic interface. public class MyLinkedList<E> { private MyNode first; ... private class MyNode { private E data; private MyNode next; } private class MyIterator implements ListIterator<E> { ... } } Which of the following statements apply? i.the code is correct II.change to private class MyIterator implements ListIterator III.change to private class MyNode<E>

(Multiple Choice)
4.9/5
(37)

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

(Multiple Choice)
4.9/5
(32)

Consider the following declaration: LinkedList<String> list = new LinkedList<>(); 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)
5.0/5
(36)

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

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

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

(Multiple Choice)
4.8/5
(37)

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

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

(Multiple Choice)
4.7/5
(39)

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 e) { first = new MyNode(); first.data = e; first.next = null; } public E getFirst() { return first.data; } private class MyNode { private E data; private MyNode next; } public static void main(String[] args) { MyLinkedList<String> list = new MyLinkedList<>("Hello"); System.out.println("List first element = " + list.getFirst()); } }

(Multiple Choice)
4.8/5
(34)

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

(Multiple Choice)
4.9/5
(34)

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

(Multiple Choice)
5.0/5
(42)

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

(Multiple Choice)
4.8/5
(32)

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

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

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

(Multiple Choice)
4.7/5
(32)

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

(Multiple Choice)
4.7/5
(38)
Showing 21 - 40 of 75
close modal

Filters

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