Exam 18: Generic Classes
Exam 1: Introduction76 Questions
Exam 2: Using Objects82 Questions
Exam 3: Implementing Classes108 Questions
Exam 4: Fundamental Data Types124 Questions
Exam 5: Decisions119 Questions
Exam 6: Loops107 Questions
Exam 7: Arrays and Array Lists117 Questions
Exam 8: Designing Classes88 Questions
Exam 9: Inheritance99 Questions
Exam 10: Interfaces100 Questions
Exam 11: Input/Output and Exception Handling108 Questions
Exam 12: Object-Oriented Design104 Questions
Exam 13: Recursion99 Questions
Exam 14: Sorting and Searching100 Questions
Exam 15: The Java Collections Framework102 Questions
Exam 16: Basic Data Structures102 Questions
Exam 17: Tree Structures102 Questions
Exam 18: Generic Classes75 Questions
Exam 19: Stream Processing85 Questions
Exam 20: Graphical User Interfaces75 Questions
Exam 21: Advanced Input/Output90 Questions
Exam 22: Multithreading81 Questions
Exam 23: Internet Networking74 Questions
Exam 24: Relational Databases75 Questions
Exam 25: XML74 Questions
Select questions type
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)
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
Filters
- Essay(0)
- Multiple Choice(0)
- Short Answer(0)
- True False(0)
- Matching(0)