Exam 18: Generic Classes
Exam 1: Introduction98 Questions
Exam 2: Using Objects76 Questions
Exam 3: Implementing Classes103 Questions
Exam 4: Fundamental Data Types125 Questions
Exam 5: Decisions120 Questions
Exam 6: Loops128 Questions
Exam 7: Arrays and Array Lists118 Questions
Exam 8: Designing Classes95 Questions
Exam 9: Inheritance101 Questions
Exam 10: Interfaces85 Questions
Exam 11: Inputoutput and Exception Handling109 Questions
Exam 12: Object-Oriented Design104 Questions
Exam 13: Recursion110 Questions
Exam 14: Sorting and Searching109 Questions
Exam 15: The Java Collections Framework110 Questions
Exam 16: Basic Data Structures104 Questions
Exam 17: Tree Structures110 Questions
Exam 18: Generic Classes75 Questions
Exam 19: Graphical User Interfaces76 Questions
Exam 20: Streams and Binary Inputoutput82 Questions
Exam 21: Multithreading82 Questions
Exam 22: Internet Networking74 Questions
Exam 23: Relational Databases75 Questions
Exam 24: XML74 Questions
Exam 25: Web Applications75 Questions
Select questions type
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.7/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<String> box = new Box<String>();
) . .
Box)insert("blue Box");
String b = (String) box.getData();
(Multiple Choice)
4.8/5
(36)
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
(41)
What does the following code snippet mean: <E extends Comparable<E> & Measurable>
(Multiple Choice)
4.8/5
(37)
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
(31)
The type variables in HashMap<K, V> in the standard library mnemonically represent ____.
(Multiple Choice)
4.9/5
(35)
Consider the following code snippet: ArrayList<BankAccount> accounts1 = new ArrayList<BankAccount>(); //Line 1
LinkedList accounts2 = new LinkedList(); //Line 2
Accounts1.add("my Salary"); //Line 3
Accounts2.addFirst("my Salary"); //Line 4
Which of the above lines will cause a compile-time error?
(Multiple Choice)
4.9/5
(34)
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
(Multiple Choice)
4.7/5
(48)
Erasure of types limits Java code somewhat with generics. Which of the following are limitations of generic code?
I cannot instantiate a type variable
II cannot return a type variable
III cannot pass a type variable
(Multiple Choice)
4.8/5
(32)
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.7/5
(28)
Which of the following statements about generic programming is NOT correct?
(Multiple Choice)
4.8/5
(33)
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)
Which of the following statements about generic programming is NOT correct?
(Multiple Choice)
4.8/5
(33)
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
(36)
Showing 61 - 75 of 75
Filters
- Essay(0)
- Multiple Choice(0)
- Short Answer(0)
- True False(0)
- Matching(0)