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
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
Free
(Multiple Choice)
4.9/5
(32)
Correct Answer:
D
Given an array myArray, which of the following represents an expression to determine the type of the elements of the array?
Free
(Multiple Choice)
4.9/5
(37)
Correct Answer:
A
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<>();
...
box.insert("blue Box");
Double myDouble = (Double) box.getData();
Free
(Multiple Choice)
4.9/5
(35)
Correct Answer:
D
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.7/5
(42)
Given the following declaration, what is the type parameter in Stack<E> replaced with?
private Stack<String> myStack = new Stack<>();
(Multiple Choice)
4.8/5
(41)
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<>();
box.insert("blue Box");
(Multiple Choice)
4.8/5
(40)
To maintain compatibility with pre-generic Java, type parameters are replaced by ordinary types called ____.
(Multiple Choice)
4.7/5
(33)
Which of the following statements about generic programming is NOT correct?
(Multiple Choice)
4.8/5
(47)
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};
print(makeArray(a));
Assume that the method call to print(makeArray(a)) works correctly by printing the int array a.Which of the following headers for the makeArray method will make this possible?
i.public static Integer[] makeArray(int[] a)
II.public static E[] makeArray(int[] a)
III.public static Integer[] makeArray(E[] a)
(Multiple Choice)
4.9/5
(48)
Which of the following statements about generic methods is NOT correct?
(Multiple Choice)
4.9/5
(34)
Consider the following code snippet:
public class Box<E>
{
private E data;
public Box(){ ...}
public void insert(E value) { ...}
}
Which of the following is a valid Box<E> object instantiation?
i.Box<Object> box = new Box<>();
II.Box<Boolean> box = new Box<>();
III.Box<double> box = new Box<>();
(Multiple Choice)
4.8/5
(35)
Suppose a linked-list class called MyLinkedList with a generic E type has been instantiated with a java.awt.Component type variable.Consider its instance method locate with the following header:
public void locate(MyLinkedList<? extends E>) { ...}
Which type cannot be passed to method locate?
i.MyLinkedList<JButton>
II.MyLinkedList<Component>
III.MyLinkedList<JTextField>
(Multiple Choice)
4.7/5
(37)
Which of the following satisfies the wildcard ? extends Object?
i.String
II.JComponent
III.Scanner
(Multiple Choice)
4.9/5
(32)
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 = box.getData();
(Multiple Choice)
4.9/5
(39)
Which of the following statements about generic methods is correct?
(Multiple Choice)
4.9/5
(29)
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.9/5
(34)
If a class requires two generic type variables, how many can you legally provide in Java?
i.0
II.1
III.2
(Multiple Choice)
4.8/5
(32)
Which of the following satisfies the wildcard ? super Object?
(Multiple Choice)
4.9/5
(37)
Which of the following statements about generic programming is NOT correct?
(Multiple Choice)
4.9/5
(45)
Showing 1 - 20 of 75
Filters
- Essay(0)
- Multiple Choice(0)
- Short Answer(0)
- True False(0)
- Matching(0)