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
Which is the purpose of the <E> element in the class declaration below?
public class Thing<E>
{
public Thing() { ...}
}
(Multiple Choice)
4.9/5
(41)
Consider the following code snippet:
Which of the above lines will cause a compile-time error?

(Multiple Choice)
4.7/5
(33)
Which of the following statements about using generic programming is NOT correct?
(Multiple Choice)
4.7/5
(40)
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
(39)
Consider the following code snippet:
public static <E extends Measurable> E min(E[] objects)
Which of the following represents the result of type erasure on this code?
(Multiple Choice)
4.9/5
(35)
Consider the following code snippet:
public class SavingsAccount extends BankAccount { ...}
public class CheckingAccount extends BankAccount { ...}
...
SavingsAccount[] savingsAccounts = new SavingsAccount[100]; //Line 1
BankAccount[] bankAccounts = savingsAccounts; //Line 2
BankAccount myAccount = new CheckingAccount(); //Line 3
bankAccounts[0] = myAccount; //Line 4
Which of the following statements regarding this code is correct?
(Multiple Choice)
4.8/5
(47)
Given an object myObject, which of the following represents the correct code to make a new instance of an object having the same class, assuming that the class has a constructor with no arguments?
(Multiple Choice)
4.9/5
(40)
Suppose a generic method accepts a generic unconstrained argument p.What restrictions are placed on p by the compiler?
(Multiple Choice)
4.8/5
(43)
Which of the following headers for a generic method myMethod allows the actionPerformed method from the ActionListener class to be called?
i.public static <E extends ActionListener> E myMethod(E e)
II.public static <E implements ActionListener> E myMethod(E e)
III.public <E extends ActionListener> E myMethod(E e)
(Multiple Choice)
4.9/5
(24)
Consider the following code snippet:
public static void reverse(List <? super E> list) { ...}
Which of the following statements about this code is correct?
(Multiple Choice)
4.8/5
(42)
Consider the following code snippet:
public class Box<E>
{
private E data;
public Box() { ...}
}
Which of the following choices is a specific type of the generic Box class?
(Multiple Choice)
4.9/5
(31)
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
(30)
Which of the following satisfies the wildcard ? extends Component?
(Multiple Choice)
4.8/5
(37)
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
(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<String> box = new Box<>();
...
box.insert("blue Box");
String b = (Object) box.getData();
(Multiple Choice)
4.8/5
(36)
Showing 61 - 75 of 75
Filters
- Essay(0)
- Multiple Choice(0)
- Short Answer(0)
- True False(0)
- Matching(0)