Exam 18: Generic Classes
Exam 1: Introduction96 Questions
Exam 2: Fundamental Data Types103 Questions
Exam 3: Decisionseasy99 Questions
Exam 4: Loops100 Questions
Exam 5: Methods94 Questions
Exam 6: Arrays and Arraylists100 Questions
Exam 7: Inputoutput and Exception Handling100 Questions
Exam 8: Objects and Classes101 Questions
Exam 9: Inheritance and Interfaces99 Questions
Exam 10: Graphical User Interfaces54 Questions
Exam 11: Advanced User Interfaces91 Questions
Exam 12: Object-Oriented Design100 Questions
Exam 13: Recursion100 Questions
Exam 14: Sorting and Searching99 Questions
Exam 15: The Java Collections Framework100 Questions
Exam 16: Basic Data Structures94 Questions
Exam 17: Tree Structures100 Questions
Exam 18: Generic Classes78 Questions
Exam 19: Streams and Binary Inputoutput82 Questions
Exam 20: Multithreading82 Questions
Exam 21: Internet Networking74 Questions
Exam 22: Relational Databases75 Questions
Exam 23: XML74 Questions
Exam 24: Web Applications74 Questions
Select questions type
Consider the following code snippet:
Public static void reverse(List list) { . . . }
Which of the following statements about this code is correct?
(Multiple Choice)
4.9/5
(35)
Which argument type cannot passed to generic methods?
I Object
II GUI components
III primitive
(Multiple Choice)
4.8/5
(43)
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
(28)
The type variables in HashMap<K, V> in the standard library mnemonically represent ____.
(Multiple Choice)
4.9/5
(37)
What does the following code snippet mean:
<E extends Comparable<E> & Measurable>
(Multiple Choice)
4.8/5
(31)
To maintain compatibility with pre-generic Java, type parameters are replaced by ordinary types called ____.
(Multiple Choice)
4.9/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.8/5
(34)
Given the following declaration, what is the type parameter in Stack<E> replaced with?
Private Stack myStack = new Stack();
(Multiple Choice)
4.7/5
(41)
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.8/5
(27)
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
(49)
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.8/5
(40)
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.8/5
(28)
Generics limit Java code somewhat. Which of the following are limitations of generic code?
I cannot declare static variables of a generic type
II cannot declare static methods of a generic type
III cannot declare static inner classes of a generic type
(Multiple Choice)
4.7/5
(51)
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
(38)
Which of these Java library classes are implemented using type variables?
I HashMap
II LinkedList
III ArrayList
(Multiple Choice)
4.7/5
(41)
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.8/5
(32)
What is known for certain about a type parameter when a method constrains it as follows?
<E extends MouseListener & MouseMotionListener>
(Multiple Choice)
5.0/5
(30)
Consider the following code snippet:
ArrayList<Double> arr = new ArrayList<Double>();
String element = arr.get(0);
Is there an error in this code?
(Multiple Choice)
4.9/5
(43)
Consider the following code snippet:
Public class LinkedList<E>
{
Private static E defaultValue; //Line 1
Public void add(E value, int n) { . . . } //Line 2
Private class Node { public String data; public Node next;)//Line 3
) . .
}
What is wrong with this code?
(Multiple Choice)
4.8/5
(30)
Showing 41 - 60 of 78
Filters
- Essay(0)
- Multiple Choice(0)
- Short Answer(0)
- True False(0)
- Matching(0)