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: ArrayList<Coin> coins1 = new ArrayList<Coin>(); //Line 1
LinkedList coins2 = new LinkedList(); //Line 2
Coins1.add("my penny"); //Line 3
Coins2.addFirst("my penny"); //Line 4
Which of the above lines will cause a run-time error when the object is retrieved elsewhere in the program?
Free
(Multiple Choice)
4.7/5
(39)
Correct Answer:
D
To maintain compatibility with pre-generic Java, type parameters are replaced by ordinary types called ____.
Free
(Multiple Choice)
4.9/5
(37)
Correct Answer:
B
Consider the following code snippet: public class Box<E>
{
Private E data;
Public Box() { . . . }
Public void insert(E value) { . . . }
}
What will result from executing the following code?
Box<Boolean> box = new Box<Boolean>();
Box)insert("blue Box");
Free
(Multiple Choice)
4.8/5
(38)
Correct Answer:
A
Given the following declaration, what is the type parameter in Stack<E> replaced with? private Stack<String> myStack = new Stack<String>();
(Multiple Choice)
4.7/5
(35)
Which of the following satisfies the wildcard ? extends Object?
I String
II JComponent
III Scanner
(Multiple Choice)
4.8/5
(36)
Which of the following necessitates the type erasure process?
I The Java virtual machine does not work with generic types
II To maintain backward compatibility to older versions of Java
III Generics do not work with primitives
(Multiple Choice)
4.9/5
(29)
What is known for certain about a type parameter when a method constrains it as follows? <E extends MouseListener & MouseMotionListener>
(Multiple Choice)
4.8/5
(35)
Which is the purpose of the <E> element in the class declaration below? public class Thing<E>
{
Public Thing() { . . . }
}
(Multiple Choice)
4.9/5
(38)
Given the following declaration, what is the type parameter in Stack<E> replaced with? private Stack myStack = new Stack();
(Multiple Choice)
4.9/5
(33)
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.7/5
(37)
Which Java technique(s) allows generic programming?
I type variables
II primitive types
III inheritance
(Multiple Choice)
4.9/5
(40)
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.7/5
(39)
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<Boolean>();
Box b = (Box) box.getData();
(Multiple Choice)
4.8/5
(43)
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
(33)
Consider the following code snippet: public static <T> void fun(T[] t) { . . . }
Erasure by the compiler of method fun will generate which result?
(Multiple Choice)
4.9/5
(30)
Which of the following satisfies the wildcard ? extends Component?
(Multiple Choice)
4.9/5
(38)
Consider the following code snippet in the LinkedList<E> class: public void addAll(LinkedList<? extends E> other)
{
ListIterator<E> iter = other.listIterator();
While (iter.hasNext())
{
Add(iter.next());
}
}
Which of the following statements about this code is correct?
(Multiple Choice)
4.9/5
(35)
What is the best technique for overcoming the restriction for the use of primitives, such as int, in generic classes and methods?
(Multiple Choice)
4.8/5
(36)
Which of the following satisfies the wildcard ? super Object?
(Multiple Choice)
4.9/5
(34)
Showing 1 - 20 of 75
Filters
- Essay(0)
- Multiple Choice(0)
- Short Answer(0)
- True False(0)
- Matching(0)