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
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.9/5
(34)
Consider the following code snippet: public class Box<E>
{
Private E data;
Public Box(){ . . . }
Public void insert(E value) { . . . }
Public E getData(){ . . . }
}
What specific exception will be thrown when the following code executes?
Box<String> box = new Box<String>();
) . .
Box)insert("blue Box");
Double myDouble = (Double) box.getData();
(Multiple Choice)
4.8/5
(33)
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};
String[] s = {"happy","cat","silly","dog"};
Boolean[] b = {"true", "true", "false"};
Which of the following are correct calls to this generic print method?
I print(a);
II print(s);
III print(b);
(Multiple Choice)
4.8/5
(44)
Consider the following code snippet: public static void reverse(List list) { . . . }
Which of the following statements about this code is correct?
(Multiple Choice)
4.7/5
(40)
Which of the following statements about generic methods is correct?
(Multiple Choice)
5.0/5
(36)
Consider the following code snippet: public class Box<E>
{
Private E data;
Public Box(){ . . . }
}
Which of the following is a valid Box<E> object instantiation?
(Multiple Choice)
4.8/5
(42)
Which argument type cannot passed to generic methods?
I Object
II GUI components
III primitive
(Multiple Choice)
4.9/5
(41)
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
(43)
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
(37)
Consider the following code snippet: public class LinkedList<E>
{
Private E defaultValue; //Line 1
Public void add(E value, int n) { . . . } //Line 2
Private static class Node { public E data; public Node next;)//Line 3
) . .
}
What is wrong with this code?
(Multiple Choice)
4.9/5
(42)
Consider the following declaration: LinkedList<String> list = new LinkedList<String>();
This declaration implies that the LinkedList class could begin with which of the following code statements?
I public class LinkedList<String> { . . . }
II public class LinkedList<S> { . . . }
III public class LinkedList<Element> { . . . }
(Multiple Choice)
4.8/5
(39)
Consider the following code snippet: public static <E extends Comparable<E>> E min(ArrayList<E> objects)
What can we conclude about the return type of this method?
(Multiple Choice)
4.7/5
(42)
Which of these Java library classes are implemented using type variables?
I HashMap
II LinkedList
III ArrayList
(Multiple Choice)
4.8/5
(26)
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.7/5
(34)
Which of the following statements about generic methods is correct?
(Multiple Choice)
4.9/5
(33)
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<Object>();
II Box<Boolean> box = new Box<Boolean>();
III Box<double> box = new Box<double>();
(Multiple Choice)
4.9/5
(35)
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)
4.9/5
(41)
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.9/5
(28)
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
(34)
Consider the following code snippet that declares the GraduateStudent class: public GraduateStudent extends Student { . . .}
Which of these statements are false?
I GraduateStudent is a subclass of Student
II Stack<GraduateStudent> is a subclass of Stack<Student>
III Stack<Student> is a subclass of Stack<GraduateStudent>
(Multiple Choice)
4.9/5
(37)
Showing 41 - 60 of 75
Filters
- Essay(0)
- Multiple Choice(0)
- Short Answer(0)
- True False(0)
- Matching(0)