Deck 18: Generic Classes

ملء الشاشة (f)
exit full mode
سؤال
Which of the following statements about generic programming is NOT correct?

A) Type parameters can be instantiated with class types.
B) Type parameters can be instantiated with interface types.
C) Type parameters can be instantiated with primitive data types.
D) Type parameters can be instantiated with wrapper class types.
استخدم زر المسافة أو
up arrow
down arrow
لقلب البطاقة.
سؤال
Consider the following code snippet:
ArrayList arr = new ArrayList();
String element = arr.get(0);
Is there an error in this code?

A) Yes, a run-time error will occur because a Double value cannot be cast to a String value.
B) Yes, a compile-time error will occur because you cannot assign a Double value to a String variable.
C) No run-time error or compile-time errors will occur.
D) You cannot create an arraylist of type Double.
سؤال
Consider the following code snippet:
ArrayList coins1 = new ArrayList(); //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 compile-time error?

A) Line 1
B) Line 2
C) Line 3
D) Line 4
سؤال
Consider the following code snippet:
Public class Box
{
Private E data;
Public Box() { . . . }
Public void insert(E value) { . . . }
Public E getData(){ . . . }
}
What will result from executing the following code?
Box box = new Box();
) . .
Box)insert("blue Box");
String b = box.getData();

A) compiler error
B) run-time error
C) no error
D) compiler warning
سؤال
Consider the following code snippet:
Public class Box
{
Private E data;
Public Box() { . . . }
Public void insert(E value) { . . . }
Public E getData(){ . . . }
}
What will result from the following code?
Box box = new Box();
) . .
Box)insert("blue Box");
Double myDouble = (Double) box.getData();

A) compiler error
B) run-time error
C) correct, but unnecessary cast
D) correct, with necessary cast
سؤال
Consider the following code snippet:
Public class Box
{
Private E data;
Public Box(){ . . . }
Public void insert(E value) { . . . }
}
Which of the following is a valid Box object instantiation?
I Box box = new Box();
II Box box = new Box();
III Box box = new Box();

A) I
B) I and II
C) I and III
D) II and III
سؤال
Which of the following statements about using generic programming is NOT correct?

A) Using type parameters makes generic code safer.
B) Using type parameters makes generic code easier to read and understand.
C) Using type parameters will potentially avoid some class cast exceptions that may occur when using collections without type parameters.
D) Type parameters cannot be used with interfaces.
سؤال
Which is the purpose of the element in the class declaration below?
Public class Thing
{
Public Thing() { . . . }
}

A) declares that only instances of E class can be stored
B) it is a type variable
C) it is an instance variable
D) it is a cast
سؤال
Which Java generic programming technique(s) requires the programmer to use casting to access variables stored as Object types?
I type variables
II primitive types
III inheritance

A) I
B) II
C) III
D) I and III
سؤال
Consider the following code snippet:
ArrayList coins1 = new ArrayList(); //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?

A) Line 1
B) Line 2
C) Line 3
D) Line 4
سؤال
Consider the following code snippet:
ArrayList accounts1 = new ArrayList(); //Line 1
LinkedList accounts2 = new LinkedList(); //Line 2
Accounts1.add("my Salary"); //Line 3
Accounts2.addFirst("my Salary"); //Line 4
Which of the above lines will cause a compile-time error?

A) Line 1
B) Line 2
C) Line 3
D) Line 4
سؤال
Consider the following code snippet:
Public class Box
{
Private E data;
Public Box() { . . . }
Public void insert(E value) { . . . }
Public E getData() { . . . }
}
What will result from executing the following code?
Box box = new Box();
Box b = (Box) box.getData();

A) compile-time error
B) run-time error
C) correct generic assignment
D) compile-time warning
سؤال
Consider the following code snippet:
Public class Box
{
Private E data;
Public Box(){ . . . }
Public void insert(E value) { . . . }
Public E getData() { . . . }
}
What will result from executing the following code?
Box box = new Box();
) . .
Box)insert("blue Box");
String b = (String) box.getData();

A) compiler error
B) run-time error
C) correct, but unnecessary cast
D) correct, with necessary cast
سؤال
Consider the following code snippet:
Public class Box
{
Private E data;
Public Box(){ . . . }
}
Which of the following is a valid Box object instantiation?

A) Box box = new Box;
B) Box box = new Box();
C) Box box = new Box();
D) Box box = new Box();
سؤال
Consider the following code snippet:
Public class Box
{
Private E data;
Public Box() { . . . }
Public void insert(E value) { . . . }
}
What will result from executing the following code?
Box box = new Box();
Box)insert("blue Box");

A) compile-time error
B) run-time error
C) correct generic assignment
D) compile-time warning
سؤال
Consider the following code snippet:
Public class Box
{
Private E data;
Public Box() { . . . }
}
Which of the following choices is a specific type of the generic Box class?

A) Box
B) Box
C) Box
D) Box
سؤال
Which Java technique(s) allows generic programming?
I type variables
II primitive types
III inheritance

A) I
B) II
C) III
D) I and III
سؤال
Which of the following statements about generic programming is NOT correct?

A) Generic classes use type parameters to achieve genericity.
B) Generic programming can be achieved by using inheritance.
C) Generic programming can be achieved by using type parameters.
D) To achieve genericity through inheritance, you must include type parameters to specify the type of object to be processed.
سؤال
Consider the following code snippet:
ArrayList accounts1 = new ArrayList(); //Line 1
LinkedList accounts2 = new LinkedList(); //Line 2
Accounts1.add("my Salary"); //Line 3
Accounts2.addFirst("my Salary"); //Line 4
Which of the above lines will cause a run-time error when the object is retrieved elsewhere in the program?

A) Line 1
B) Line 2
C) Line 3
D) Line 4
سؤال
Consider the following code snippet:
Public class Box
{
Private E data;
Public Box(){ . . . }
Public void insert(E value) { . . . }
Public E getData(){ . . . }
}
What will result from executing the following code?
Box box = new Box();
) . .
Box)insert("blue Box");
String b = (Object) box.getData();

A) compiler error
B) run-time error
C) correct, but unnecessary cast
D) correct, with necessary cast
سؤال
Consider the following code snippet:
Public static 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);

A) I
B) I and II
C) II and III
D) I, II and III
سؤال
Which of these Java library classes are implemented using type variables?
I HashMap
II LinkedList
III ArrayList

A) I and II
B) II and III
C) I and III
D) I, II and III
سؤال
Deep Check
Select the correct header for this generic print method.
Public static void print(E[]
A)
A)
A)
A) {
For (int i = 0; i < a.length; i++)
{
System.out.println(a[i] + " ");
}
}

A) public static void print(E[]
سؤال
The type variables in HashMap in the standard library mnemonically represent ____.

A) kernel and vector
B) key and value
C) kind and variable
D) String and Vector
سؤال
Consider our own generic class MyLinkedList shown below. It has a private Node class, and it implements the standard Java ListIterator generic interface.
Public class MyLinkedList
{
Private MyNode first;
) . .
Private class MyNode
{
Private E data;
Private MyNode next;
}
Private class MyIterator implements ListIterator
{
) . .
}
}
Which of the following statements apply?
I the code is correct
II change to private class MyIterator implements ListIterator
III change to private class MyNode

A) I
B) II
C) III
D) II and III
سؤال
Determine the correctness of the MyLinkedList generic class code below.
Public class MyLinkedList
{
Private MyNode first;
Public E getFirst() { return first.data; }
Private class MyNode
{
Private E data;
Private MyNode next;
}
}

A) MyNode cannot refer to type variable E
B) first.data will cause a compiler error
C) the inner class MyNode cannot be private
D) the code is correct
سؤال
Which argument type cannot passed to generic methods?
I Object
II GUI components
III primitive

A) I
B) II
C) III
D) I and III
سؤال
Which of the following statements about generic methods is correct?

A) A generic method must reside in a generic class.
B) A generic method must have a generic type argument.
C) A generic method must have a generic type parameter.
D) The generic type parameter of a generic method designates the method's return type.
سؤال
Determine the output of the MyLinkedList generic class code below when the main method executes.
Public class MyLinkedList
{
Private MyNode first;
Public MyLinkedList(E

A) List first element = Hello
B) List first element = null
C) compiler error is generated by first = new MyNode();
D) no output
E) {
First = new MyNode();
First.data = e;
First.next = null;
}
Public E getFirst() { return first.data; }
Private class MyNode
{
Private E data;
Private MyNode next;
}
Public static void main(String[] args)
{
MyLinkedList list = new MyLinkedList("Hello");
System.out.println("List first element = " + list.getFirst());
}
}
سؤال
Deep Check
Consider the following code snippet:
Public static void print(E[]
A)
A) II public static E[] makeArray(int[]
A) III public static Integer[] makeArray(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) I
سؤال
In Java, generic programming can be achieved with ____.

A) encapsulation
B) inheritance
C) polymorphism
D) arrays
سؤال
Consider the following code snippet:
Public class Box
{
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 box = new Box();
) . .
Box)insert("blue Box");
Double myDouble = (Double) box.getData();

A) Exception
B) NoSuchElementException
C) IndexOutOfBoundsException
D) ClassCastException
سؤال
Which of the following statements regarding restrictions for generic methods are true?
I Generic methods must be declared inside a generic class.
II Generic methods must be static.
III Generic methods may only have one generic parameter.

A) I
B) I and II
C) II and III
D) none are restrictions
سؤال
What is the best technique for overcoming the restriction for the use of primitives, such as int, in generic classes and methods?

A) use of the Object type
B) use of wrapper classes
C) use String and decode values with a method such as Integer.parseInt
D) do not use generic methods when using primitives
سؤال
Deep Check
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 myMethod(E

A) I
B) II
C) III
D) I and III
E)
سؤال
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

A) I and III
B) II and III
C) I, II and III
D) none are necessary
سؤال
Consider the following declaration:
LinkedList list = new LinkedList();
This declaration implies that the LinkedList class could begin with which of the following code statements?
I public class LinkedList { . . . }
II public class LinkedList { . . . }
III public class LinkedList { . . . }

A) I
B) II
C) III
D) II and III
سؤال
What is known for certain about a type parameter when a method constrains it as follows?

A) it is either a MouseListener or MouseMotionListener implementer
B) it implements MouseListener and MouseMotionListener
C) it is of type MouseEvent
D) the code is illegal; the & symbol should read and
سؤال
What is known for certain about Visualizer when a method constrains its type parameter as follows?

A) Visualizer must refer to a class
B) Visualizer must refer to an interface
C) Visualizer can refer to either an interface or a class
D) Visualizer is another generic type
سؤال
Which of the following statements about generic methods is correct?

A) You must instantiate the type parameter when calling a generic method.
B) You must specify which type to use when calling a generic method.
C) Generic methods cannot be static methods.
D) You cannot replace type parameters with primitive types.
سؤال
Consider the following code snippet:
Public static > E min(ArrayList objects)
What can we conclude about the return type of this method?

A) The return type is a class that extends Comparable.
B) The return type is a class that implements Comparable.
C) The return type is an array list of generic objects.
D) The return type is a subclass of the ArrayList class.
سؤال
Which of the following is not a wildcard type?

A) ?
B) ? super B
C) ? sub B
D) ? extends B
سؤال
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?

A) Line 2 will cause a compile-time error.
B) Line 2 will cause a run-time error.
C) Line 4 will cause a compile-time error.
D) Line 4 will cause a run-time error.
سؤال
What does it mean when the syntax ? extends D is used?

A) Any superclass of D may be used.
B) Any subclass of D may be used.
C) Any subclass or superclass of D may be used.
D) This indicates a wildcard with an upper bound
سؤال
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 is a subclass of Stack
III Stack is a subclass of Stack

A) I
B) II
C) III
D) II and III
سؤال
Which of the following satisfies the wildcard ? extends Component?

A) String
B) Scanner
C) JButton
D) Color
سؤال
Which of the following satisfies the wildcard ? super Object?

A) String
B) JComponent
C) Scanner
D) none satisfy this wildcard
سؤال
Given the following generic method, which of the following is a possible return type?
Public static E max(E[]
A) I

A) { . . . }
I String
II Object
III Double
B) II
C) I and II
D) I and III
سؤال
Which code is the equivalent of the following method header?
Public static void abc(Stack stack) { . . . }
I public static void abc(Stack stack) { . . . }
II public static void abc (Stack stack) { . . . }
III public static void abc(Stack stack) { . . . }

A) I
B) II
C) III
D) I and III
سؤال
Consider the following class declaration:
Public class SavingsAccount extends BankAccount { . . . }
Which of the following statements about these classes is correct?

A) ArrayList is a subclass of ArrayList.
B) ArrayList is a subclass of ArrayList.
C) ArrayList extends ArrayList.
D) There is no relationship between ArrayList and ArrayList
سؤال
Consider the following code snippet:
Public static void reverse(List list) { . . . }
This method declaration is equivalent to which of the following declarations?

A) public static void reverse(List list) { . . . }
B) public static void reverse(List list) { . . . }
C) public static void reverse(List list) { . . . }
D) public static void reverse(List list) { . . . }
سؤال
Consider the following code snippet:
Public static void reverse(List list) { . . . }
Which of the following statements about this code is correct?

A) This is an example of a wildcard with an upper bound.
B) This is an example of a wildcard with a lower bound.
C) This is an example of an unbounded wildcard.
D) This code is illegal.
سؤال
What does the following code snippet mean:
& Measurable>

A) The class represented by E extends Comparable and Measurable.
B) The class represented by E implements Comparable and Measurable.
C) The class represented by E implements Comparable and extends Measurable.
D) The class represented by E extends Comparable and implements Measurable.
سؤال
Suppose a linked-list class with a generic E type has been constructed with a java.awt.Component type variable. Consider its instance method locate with the following header:
Public void locate(MyLinkedList) { . . . }
Which type cannot be passed to method locate?
I MyLinkedList
II MyLinkedList
III MyLinkedList

A) I
B) I and II
C) II and III
D) all can be passed to locate
سؤال
What does it mean when the syntax ? super D is used?

A) Any superclass of D may be used.
B) Any subclass of D may be used.
C) Any subclass or superclass of D may be used.
D) This indicates a wildcard with a lower bound
سؤال
Which of the following satisfies the wildcard ? extends Object?
I String
II JComponent
III Scanner

A) I
B) II
C) I and II
D) I, II and III
سؤال
Consider the following code snippet in the LinkedList class:
Public void addAll(LinkedList other)
{
ListIterator iter = other.listIterator();
While (iter.hasNext())
{
Add(iter.next());
}
}
Which of the following statements about this code is correct?

A) You must supply a specific type for the element type of other.
B) For the element type of other, you must supply a type that is a subtype of E.
C) For the element type of other, you must supply a type that is a supertype of E.
D) For the element type of other, you must supply a type that is either a subtype or a supertype of E.
سؤال
Given the following generic method, which of the following CANNOT be the return type?
Public static E max(E[]
A) I

A) { . . .}
I String
II Integer
III double
B) II
C) III
D) I and III
سؤال
Consider the following code snippet:
Public static void reverse(List list) { . . . }
Which of the following statements about this code is correct?

A) This is an example of a wildcard with an upper bound.
B) This is an example of a wildcard with a lower bound.
C) This is an example of an unbounded wildcard.
D) This code is illegal.
سؤال
Consider the following code snippet:
Public static void reverse(List list) { . . . }
Which of the following statements about this code is correct?

A) This is an example of a wildcard with an upper bound.
B) This is an example of a wildcard with a lower bound.
C) This is an example of an unbounded wildcard.
D) This code is illegal.
سؤال
Consider the following code snippet:
Public static void fun(T[] t) { . . . }
Erasure by the compiler of method fun will generate which result?

A) public static void fun(Object[] t) { . . . }
B) public static void fun(Object t) { . . . }
C) public static void fun(Object[] t) { . . . }
D) public static void fun(Object t) { . . . }
سؤال
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

A) I
B) II
C) III
D) II and III
سؤال
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

A) I
B) II
C) I and II
D) I, II, and III
سؤال
Consider the following code snippet:
Public class LinkedList
{
Private E defaultValue;
Public static List replicate(E value, int n) { . . . }
Private class Node { public String data; public Node next;)
) . .
}
What is wrong with this code?

A) Cannot declare the variable defaultValue as a generic type.
B) Cannot pass a generic type as an argument to a method.
C) Cannot have a static method in a generic class as shown.
D) Cannot have an inner class in a generic class.
سؤال
Consider the following code snippet:
Public static E min(E[] objects)
Which of the following represents the result of type erasure on this code?

A) public static Measurable E min(Measurable E[] objects)
B) public static Measurable min(Measurable[] objects)
C) public static E min(Measurable E[] objects)
D) This code is illegal and type erasure will not occur.
سؤال
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

A) I
B) II
C) I and II
D) I and III
سؤال
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

A) I
B) II
C) III
D) I and III
سؤال
Given the following declaration, what is the type parameter in Stack replaced with?
Private Stack myStack = new Stack();

A) String
B) Object
C) int
D) Stack
سؤال
To maintain compatibility with pre-generic Java, type parameters are replaced by ordinary types called ____.

A) primitives
B) raw types
C) Object
D) generics
سؤال
Consider the following code snippet:
Public class LinkedList
{
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?

A) Cannot declare the variable defaultValue as a generic type.
B) Cannot pass a generic type as an argument to a method.
C) Cannot have a static method in a generic class as shown.
D) Cannot have a static inner class in a generic class as shown.
سؤال
Given the following declaration, what is the type parameter in Stack replaced with?
Private Stack myStack = new Stack();

A) String
B) Object
C) int
D) it is a compiler error
سؤال
Suppose a generic method accepts a generic unconstrained argument p. What restrictions are placed on p by the compiler?

A) Can only execute Object class methods.
B) Can only execute methods from its own class.
C) Can not execute any methods.
D) There are no restrictions.
سؤال
If a class requires two generic type variables, how many can you legally provide in Java?
I 0
II 1
III 2

A) I
B) II
C) I and II
D) I and III
سؤال
Consider the following code snippet:
Public interface MyInterface { . . . }
Public interface YourInterface extends MyInterface { . . . }
Which of these are legal class declarations?
I public class SomeClass implements YourInterface { . . . }
II public class SomeClass implements YourInterface { . . . }
III public class SomeClass implements YourInterface { . . . }

A) I
B) III
C) I and II
D) I and III
سؤال
Generics limit Java code somewhat. Which of the following are considered limitations of generic code?
I cannot have an array of a generic type
II cannot have primitive type variables
III cannot construct an object of a generic type

A) I
B) II
C) III
D) I, II and III
سؤال
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.

A) I
B) II
C) III
D) I and III
سؤال
Which of the following statements about the Java virtual machine is correct?

A) The Java virtual machine always replaces type parameters with their upper bounds.
B) The Java virtual machine always replaces type parameters with their lower bounds.
C) The Java virtual machine always replaces type parameters with type Object.
D) The Java virtual machine replaces type parameters with their bounds or with type Object.
سؤال
Consider the following code snippet:
Public class LinkedList
{
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?

A) Cannot declare the variable defaultValue as static.
B) Cannot pass a generic type as an argument to a method as shown.
C) Cannot have an inner class in a generic class as shown.
D) Cannot declare the variable defaultValue as a generic data type.
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/78
auto play flashcards
العب
simple tutorial
ملء الشاشة (f)
exit full mode
Deck 18: Generic Classes
1
Which of the following statements about generic programming is NOT correct?

A) Type parameters can be instantiated with class types.
B) Type parameters can be instantiated with interface types.
C) Type parameters can be instantiated with primitive data types.
D) Type parameters can be instantiated with wrapper class types.
C
2
Consider the following code snippet:
ArrayList arr = new ArrayList();
String element = arr.get(0);
Is there an error in this code?

A) Yes, a run-time error will occur because a Double value cannot be cast to a String value.
B) Yes, a compile-time error will occur because you cannot assign a Double value to a String variable.
C) No run-time error or compile-time errors will occur.
D) You cannot create an arraylist of type Double.
B
3
Consider the following code snippet:
ArrayList coins1 = new ArrayList(); //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 compile-time error?

A) Line 1
B) Line 2
C) Line 3
D) Line 4
C
4
Consider the following code snippet:
Public class Box
{
Private E data;
Public Box() { . . . }
Public void insert(E value) { . . . }
Public E getData(){ . . . }
}
What will result from executing the following code?
Box box = new Box();
) . .
Box)insert("blue Box");
String b = box.getData();

A) compiler error
B) run-time error
C) no error
D) compiler warning
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
5
Consider the following code snippet:
Public class Box
{
Private E data;
Public Box() { . . . }
Public void insert(E value) { . . . }
Public E getData(){ . . . }
}
What will result from the following code?
Box box = new Box();
) . .
Box)insert("blue Box");
Double myDouble = (Double) box.getData();

A) compiler error
B) run-time error
C) correct, but unnecessary cast
D) correct, with necessary cast
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
6
Consider the following code snippet:
Public class Box
{
Private E data;
Public Box(){ . . . }
Public void insert(E value) { . . . }
}
Which of the following is a valid Box object instantiation?
I Box box = new Box();
II Box box = new Box();
III Box box = new Box();

A) I
B) I and II
C) I and III
D) II and III
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
7
Which of the following statements about using generic programming is NOT correct?

A) Using type parameters makes generic code safer.
B) Using type parameters makes generic code easier to read and understand.
C) Using type parameters will potentially avoid some class cast exceptions that may occur when using collections without type parameters.
D) Type parameters cannot be used with interfaces.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
8
Which is the purpose of the element in the class declaration below?
Public class Thing
{
Public Thing() { . . . }
}

A) declares that only instances of E class can be stored
B) it is a type variable
C) it is an instance variable
D) it is a cast
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
9
Which Java generic programming technique(s) requires the programmer to use casting to access variables stored as Object types?
I type variables
II primitive types
III inheritance

A) I
B) II
C) III
D) I and III
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
10
Consider the following code snippet:
ArrayList coins1 = new ArrayList(); //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?

A) Line 1
B) Line 2
C) Line 3
D) Line 4
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
11
Consider the following code snippet:
ArrayList accounts1 = new ArrayList(); //Line 1
LinkedList accounts2 = new LinkedList(); //Line 2
Accounts1.add("my Salary"); //Line 3
Accounts2.addFirst("my Salary"); //Line 4
Which of the above lines will cause a compile-time error?

A) Line 1
B) Line 2
C) Line 3
D) Line 4
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
12
Consider the following code snippet:
Public class Box
{
Private E data;
Public Box() { . . . }
Public void insert(E value) { . . . }
Public E getData() { . . . }
}
What will result from executing the following code?
Box box = new Box();
Box b = (Box) box.getData();

A) compile-time error
B) run-time error
C) correct generic assignment
D) compile-time warning
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
13
Consider the following code snippet:
Public class Box
{
Private E data;
Public Box(){ . . . }
Public void insert(E value) { . . . }
Public E getData() { . . . }
}
What will result from executing the following code?
Box box = new Box();
) . .
Box)insert("blue Box");
String b = (String) box.getData();

A) compiler error
B) run-time error
C) correct, but unnecessary cast
D) correct, with necessary cast
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
14
Consider the following code snippet:
Public class Box
{
Private E data;
Public Box(){ . . . }
}
Which of the following is a valid Box object instantiation?

A) Box box = new Box;
B) Box box = new Box();
C) Box box = new Box();
D) Box box = new Box();
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
15
Consider the following code snippet:
Public class Box
{
Private E data;
Public Box() { . . . }
Public void insert(E value) { . . . }
}
What will result from executing the following code?
Box box = new Box();
Box)insert("blue Box");

A) compile-time error
B) run-time error
C) correct generic assignment
D) compile-time warning
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
16
Consider the following code snippet:
Public class Box
{
Private E data;
Public Box() { . . . }
}
Which of the following choices is a specific type of the generic Box class?

A) Box
B) Box
C) Box
D) Box
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
17
Which Java technique(s) allows generic programming?
I type variables
II primitive types
III inheritance

A) I
B) II
C) III
D) I and III
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
18
Which of the following statements about generic programming is NOT correct?

A) Generic classes use type parameters to achieve genericity.
B) Generic programming can be achieved by using inheritance.
C) Generic programming can be achieved by using type parameters.
D) To achieve genericity through inheritance, you must include type parameters to specify the type of object to be processed.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
19
Consider the following code snippet:
ArrayList accounts1 = new ArrayList(); //Line 1
LinkedList accounts2 = new LinkedList(); //Line 2
Accounts1.add("my Salary"); //Line 3
Accounts2.addFirst("my Salary"); //Line 4
Which of the above lines will cause a run-time error when the object is retrieved elsewhere in the program?

A) Line 1
B) Line 2
C) Line 3
D) Line 4
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
20
Consider the following code snippet:
Public class Box
{
Private E data;
Public Box(){ . . . }
Public void insert(E value) { . . . }
Public E getData(){ . . . }
}
What will result from executing the following code?
Box box = new Box();
) . .
Box)insert("blue Box");
String b = (Object) box.getData();

A) compiler error
B) run-time error
C) correct, but unnecessary cast
D) correct, with necessary cast
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
21
Consider the following code snippet:
Public static 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);

A) I
B) I and II
C) II and III
D) I, II and III
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
22
Which of these Java library classes are implemented using type variables?
I HashMap
II LinkedList
III ArrayList

A) I and II
B) II and III
C) I and III
D) I, II and III
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
23
Deep Check
Select the correct header for this generic print method.
Public static void print(E[]
A)
A)
A)
A) {
For (int i = 0; i < a.length; i++)
{
System.out.println(a[i] + " ");
}
}

A) public static void print(E[]
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
24
The type variables in HashMap in the standard library mnemonically represent ____.

A) kernel and vector
B) key and value
C) kind and variable
D) String and Vector
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
25
Consider our own generic class MyLinkedList shown below. It has a private Node class, and it implements the standard Java ListIterator generic interface.
Public class MyLinkedList
{
Private MyNode first;
) . .
Private class MyNode
{
Private E data;
Private MyNode next;
}
Private class MyIterator implements ListIterator
{
) . .
}
}
Which of the following statements apply?
I the code is correct
II change to private class MyIterator implements ListIterator
III change to private class MyNode

A) I
B) II
C) III
D) II and III
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
26
Determine the correctness of the MyLinkedList generic class code below.
Public class MyLinkedList
{
Private MyNode first;
Public E getFirst() { return first.data; }
Private class MyNode
{
Private E data;
Private MyNode next;
}
}

A) MyNode cannot refer to type variable E
B) first.data will cause a compiler error
C) the inner class MyNode cannot be private
D) the code is correct
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
27
Which argument type cannot passed to generic methods?
I Object
II GUI components
III primitive

A) I
B) II
C) III
D) I and III
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
28
Which of the following statements about generic methods is correct?

A) A generic method must reside in a generic class.
B) A generic method must have a generic type argument.
C) A generic method must have a generic type parameter.
D) The generic type parameter of a generic method designates the method's return type.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
29
Determine the output of the MyLinkedList generic class code below when the main method executes.
Public class MyLinkedList
{
Private MyNode first;
Public MyLinkedList(E

A) List first element = Hello
B) List first element = null
C) compiler error is generated by first = new MyNode();
D) no output
E) {
First = new MyNode();
First.data = e;
First.next = null;
}
Public E getFirst() { return first.data; }
Private class MyNode
{
Private E data;
Private MyNode next;
}
Public static void main(String[] args)
{
MyLinkedList list = new MyLinkedList("Hello");
System.out.println("List first element = " + list.getFirst());
}
}
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
30
Deep Check
Consider the following code snippet:
Public static void print(E[]
A)
A) II public static E[] makeArray(int[]
A) III public static Integer[] makeArray(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) I
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
31
In Java, generic programming can be achieved with ____.

A) encapsulation
B) inheritance
C) polymorphism
D) arrays
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
32
Consider the following code snippet:
Public class Box
{
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 box = new Box();
) . .
Box)insert("blue Box");
Double myDouble = (Double) box.getData();

A) Exception
B) NoSuchElementException
C) IndexOutOfBoundsException
D) ClassCastException
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
33
Which of the following statements regarding restrictions for generic methods are true?
I Generic methods must be declared inside a generic class.
II Generic methods must be static.
III Generic methods may only have one generic parameter.

A) I
B) I and II
C) II and III
D) none are restrictions
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
34
What is the best technique for overcoming the restriction for the use of primitives, such as int, in generic classes and methods?

A) use of the Object type
B) use of wrapper classes
C) use String and decode values with a method such as Integer.parseInt
D) do not use generic methods when using primitives
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
35
Deep Check
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 myMethod(E

A) I
B) II
C) III
D) I and III
E)
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
36
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

A) I and III
B) II and III
C) I, II and III
D) none are necessary
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
37
Consider the following declaration:
LinkedList list = new LinkedList();
This declaration implies that the LinkedList class could begin with which of the following code statements?
I public class LinkedList { . . . }
II public class LinkedList { . . . }
III public class LinkedList { . . . }

A) I
B) II
C) III
D) II and III
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
38
What is known for certain about a type parameter when a method constrains it as follows?

A) it is either a MouseListener or MouseMotionListener implementer
B) it implements MouseListener and MouseMotionListener
C) it is of type MouseEvent
D) the code is illegal; the & symbol should read and
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
39
What is known for certain about Visualizer when a method constrains its type parameter as follows?

A) Visualizer must refer to a class
B) Visualizer must refer to an interface
C) Visualizer can refer to either an interface or a class
D) Visualizer is another generic type
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
40
Which of the following statements about generic methods is correct?

A) You must instantiate the type parameter when calling a generic method.
B) You must specify which type to use when calling a generic method.
C) Generic methods cannot be static methods.
D) You cannot replace type parameters with primitive types.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
41
Consider the following code snippet:
Public static > E min(ArrayList objects)
What can we conclude about the return type of this method?

A) The return type is a class that extends Comparable.
B) The return type is a class that implements Comparable.
C) The return type is an array list of generic objects.
D) The return type is a subclass of the ArrayList class.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
42
Which of the following is not a wildcard type?

A) ?
B) ? super B
C) ? sub B
D) ? extends B
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
43
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?

A) Line 2 will cause a compile-time error.
B) Line 2 will cause a run-time error.
C) Line 4 will cause a compile-time error.
D) Line 4 will cause a run-time error.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
44
What does it mean when the syntax ? extends D is used?

A) Any superclass of D may be used.
B) Any subclass of D may be used.
C) Any subclass or superclass of D may be used.
D) This indicates a wildcard with an upper bound
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
45
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 is a subclass of Stack
III Stack is a subclass of Stack

A) I
B) II
C) III
D) II and III
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
46
Which of the following satisfies the wildcard ? extends Component?

A) String
B) Scanner
C) JButton
D) Color
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
47
Which of the following satisfies the wildcard ? super Object?

A) String
B) JComponent
C) Scanner
D) none satisfy this wildcard
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
48
Given the following generic method, which of the following is a possible return type?
Public static E max(E[]
A) I

A) { . . . }
I String
II Object
III Double
B) II
C) I and II
D) I and III
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
49
Which code is the equivalent of the following method header?
Public static void abc(Stack stack) { . . . }
I public static void abc(Stack stack) { . . . }
II public static void abc (Stack stack) { . . . }
III public static void abc(Stack stack) { . . . }

A) I
B) II
C) III
D) I and III
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
50
Consider the following class declaration:
Public class SavingsAccount extends BankAccount { . . . }
Which of the following statements about these classes is correct?

A) ArrayList is a subclass of ArrayList.
B) ArrayList is a subclass of ArrayList.
C) ArrayList extends ArrayList.
D) There is no relationship between ArrayList and ArrayList
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
51
Consider the following code snippet:
Public static void reverse(List list) { . . . }
This method declaration is equivalent to which of the following declarations?

A) public static void reverse(List list) { . . . }
B) public static void reverse(List list) { . . . }
C) public static void reverse(List list) { . . . }
D) public static void reverse(List list) { . . . }
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
52
Consider the following code snippet:
Public static void reverse(List list) { . . . }
Which of the following statements about this code is correct?

A) This is an example of a wildcard with an upper bound.
B) This is an example of a wildcard with a lower bound.
C) This is an example of an unbounded wildcard.
D) This code is illegal.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
53
What does the following code snippet mean:
& Measurable>

A) The class represented by E extends Comparable and Measurable.
B) The class represented by E implements Comparable and Measurable.
C) The class represented by E implements Comparable and extends Measurable.
D) The class represented by E extends Comparable and implements Measurable.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
54
Suppose a linked-list class with a generic E type has been constructed with a java.awt.Component type variable. Consider its instance method locate with the following header:
Public void locate(MyLinkedList) { . . . }
Which type cannot be passed to method locate?
I MyLinkedList
II MyLinkedList
III MyLinkedList

A) I
B) I and II
C) II and III
D) all can be passed to locate
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
55
What does it mean when the syntax ? super D is used?

A) Any superclass of D may be used.
B) Any subclass of D may be used.
C) Any subclass or superclass of D may be used.
D) This indicates a wildcard with a lower bound
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
56
Which of the following satisfies the wildcard ? extends Object?
I String
II JComponent
III Scanner

A) I
B) II
C) I and II
D) I, II and III
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
57
Consider the following code snippet in the LinkedList class:
Public void addAll(LinkedList other)
{
ListIterator iter = other.listIterator();
While (iter.hasNext())
{
Add(iter.next());
}
}
Which of the following statements about this code is correct?

A) You must supply a specific type for the element type of other.
B) For the element type of other, you must supply a type that is a subtype of E.
C) For the element type of other, you must supply a type that is a supertype of E.
D) For the element type of other, you must supply a type that is either a subtype or a supertype of E.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
58
Given the following generic method, which of the following CANNOT be the return type?
Public static E max(E[]
A) I

A) { . . .}
I String
II Integer
III double
B) II
C) III
D) I and III
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
59
Consider the following code snippet:
Public static void reverse(List list) { . . . }
Which of the following statements about this code is correct?

A) This is an example of a wildcard with an upper bound.
B) This is an example of a wildcard with a lower bound.
C) This is an example of an unbounded wildcard.
D) This code is illegal.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
60
Consider the following code snippet:
Public static void reverse(List list) { . . . }
Which of the following statements about this code is correct?

A) This is an example of a wildcard with an upper bound.
B) This is an example of a wildcard with a lower bound.
C) This is an example of an unbounded wildcard.
D) This code is illegal.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
61
Consider the following code snippet:
Public static void fun(T[] t) { . . . }
Erasure by the compiler of method fun will generate which result?

A) public static void fun(Object[] t) { . . . }
B) public static void fun(Object t) { . . . }
C) public static void fun(Object[] t) { . . . }
D) public static void fun(Object t) { . . . }
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
62
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

A) I
B) II
C) III
D) II and III
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
63
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

A) I
B) II
C) I and II
D) I, II, and III
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
64
Consider the following code snippet:
Public class LinkedList
{
Private E defaultValue;
Public static List replicate(E value, int n) { . . . }
Private class Node { public String data; public Node next;)
) . .
}
What is wrong with this code?

A) Cannot declare the variable defaultValue as a generic type.
B) Cannot pass a generic type as an argument to a method.
C) Cannot have a static method in a generic class as shown.
D) Cannot have an inner class in a generic class.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
65
Consider the following code snippet:
Public static E min(E[] objects)
Which of the following represents the result of type erasure on this code?

A) public static Measurable E min(Measurable E[] objects)
B) public static Measurable min(Measurable[] objects)
C) public static E min(Measurable E[] objects)
D) This code is illegal and type erasure will not occur.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
66
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

A) I
B) II
C) I and II
D) I and III
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
67
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

A) I
B) II
C) III
D) I and III
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
68
Given the following declaration, what is the type parameter in Stack replaced with?
Private Stack myStack = new Stack();

A) String
B) Object
C) int
D) Stack
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
69
To maintain compatibility with pre-generic Java, type parameters are replaced by ordinary types called ____.

A) primitives
B) raw types
C) Object
D) generics
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
70
Consider the following code snippet:
Public class LinkedList
{
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?

A) Cannot declare the variable defaultValue as a generic type.
B) Cannot pass a generic type as an argument to a method.
C) Cannot have a static method in a generic class as shown.
D) Cannot have a static inner class in a generic class as shown.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
71
Given the following declaration, what is the type parameter in Stack replaced with?
Private Stack myStack = new Stack();

A) String
B) Object
C) int
D) it is a compiler error
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
72
Suppose a generic method accepts a generic unconstrained argument p. What restrictions are placed on p by the compiler?

A) Can only execute Object class methods.
B) Can only execute methods from its own class.
C) Can not execute any methods.
D) There are no restrictions.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
73
If a class requires two generic type variables, how many can you legally provide in Java?
I 0
II 1
III 2

A) I
B) II
C) I and II
D) I and III
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
74
Consider the following code snippet:
Public interface MyInterface { . . . }
Public interface YourInterface extends MyInterface { . . . }
Which of these are legal class declarations?
I public class SomeClass implements YourInterface { . . . }
II public class SomeClass implements YourInterface { . . . }
III public class SomeClass implements YourInterface { . . . }

A) I
B) III
C) I and II
D) I and III
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
75
Generics limit Java code somewhat. Which of the following are considered limitations of generic code?
I cannot have an array of a generic type
II cannot have primitive type variables
III cannot construct an object of a generic type

A) I
B) II
C) III
D) I, II and III
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
76
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.

A) I
B) II
C) III
D) I and III
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
77
Which of the following statements about the Java virtual machine is correct?

A) The Java virtual machine always replaces type parameters with their upper bounds.
B) The Java virtual machine always replaces type parameters with their lower bounds.
C) The Java virtual machine always replaces type parameters with type Object.
D) The Java virtual machine replaces type parameters with their bounds or with type Object.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
78
Consider the following code snippet:
Public class LinkedList
{
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?

A) Cannot declare the variable defaultValue as static.
B) Cannot pass a generic type as an argument to a method as shown.
C) Cannot have an inner class in a generic class as shown.
D) Cannot declare the variable defaultValue as a generic data type.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.
فتح الحزمة
k this deck
locked card icon
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 78 في هذه المجموعة.