Exam 18: Generic Classes

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

Given the following generic method, which of the following is a possible return type? public static <E extends Comparable<E>> E max(E[] a) { ...} i.String II.Object III.Double

(Multiple Choice)
4.9/5
(29)

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

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

(Multiple Choice)
4.8/5
(44)

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<>(); ... box.insert("blue Box"); String b = (String) box.getData();

(Multiple Choice)
4.9/5
(42)

In Java, generic programming can be achieved with ____.

(Multiple Choice)
4.8/5
(35)

Which of the following is not a wildcard type?

(Multiple Choice)
4.9/5
(34)

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

(Multiple Choice)
4.8/5
(33)

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)
5.0/5
(29)

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<>(); ... box.insert("blue Box"); Double myDouble = (Double) box.getData();

(Multiple Choice)
4.8/5
(44)

Select the correct header for this generic print method. public static void print(E[] a) { for (int i = 0; i < a.length; i++) { System.out.println(a[i] + " "); } }

(Multiple Choice)
4.9/5
(34)

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

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

Which argument type cannot be passed to generic methods? i.Object II.GUI components III.primitive

(Multiple Choice)
4.7/5
(29)

Which of the following statements about the Java virtual machine is correct?

(Multiple Choice)
4.8/5
(33)

Consider the following code snippet: ArrayList<Double> arr = new ArrayList<>(); String element = arr.get(0); Is there an error in this code?

(Multiple Choice)
4.8/5
(42)

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

(Multiple Choice)
4.8/5
(55)

Which of the following are restrictions of Java generic programming? i.You cannot use the assignment operator = to assign one generic object to another. II.You cannot use the == operator to compare two generic objects. III.You cannot construct arrays of generic types.

(Multiple Choice)
4.9/5
(36)

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

(Multiple Choice)
4.8/5
(35)

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
(40)
Showing 41 - 60 of 75
close modal

Filters

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