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 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.9/5
(37)
What is the result when a program constructs a generic class without passing a type variable, as in the following code?
Stack stack = new Stack();
I the program will compile and run
II the compiler will issue an error
III the compiler will issue a warning
(Multiple Choice)
4.7/5
(35)
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 = (Object) box.getData();
(Multiple Choice)
4.8/5
(41)
Consider the following code snippet:
Public static void reverse(List<?> list) { . . . }
This method declaration is equivalent to which of the following declarations?
(Multiple Choice)
4.9/5
(42)
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.8/5
(33)
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
(39)
Consider the following code snippet:
Public interface MyInterface<E> { . . . }
Public interface YourInterface<E, T> extends MyInterface<E> { . . . }
Which of these are legal class declarations?
I public class SomeClass implements YourInterface<String, Double> { . . . }
II public class SomeClass implements YourInterface { . . . }
III public class SomeClass implements YourInterface<String> { . . . }
(Multiple Choice)
5.0/5
(40)
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
(29)
Which of the following satisfies the wildcard ? super Object?
(Multiple Choice)
4.9/5
(36)
Which of the following are restrictions of Java generic programming?
I You cannot use the assignment operator = to assign one generic object to another.
II You cannot use the == operator to compare two generic objects.
III You cannot construct arrays of generic types.
(Multiple Choice)
4.8/5
(36)
Which Java technique(s) allows generic programming?
I type variables
II primitive types
III inheritance
(Multiple Choice)
4.8/5
(42)
Which of the following statements about generic programming is NOT correct?
(Multiple Choice)
4.8/5
(29)
Which of the following statements about generic methods is correct?
(Multiple Choice)
4.8/5
(37)
Which of the following statements about generic programming is NOT correct?
(Multiple Choice)
4.8/5
(42)
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
(34)
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.8/5
(36)
Suppose a generic method accepts a generic unconstrained argument p. What restrictions are placed on p by the compiler?
(Multiple Choice)
4.9/5
(40)
Which of the following statements about the Java virtual machine is correct?
(Multiple Choice)
4.8/5
(42)
Showing 21 - 40 of 78
Filters
- Essay(0)
- Multiple Choice(0)
- Short Answer(0)
- True False(0)
- Matching(0)