Fill in the code in Comparable______ c = new Date();
C.Date
Suppose List list = new ArrayList. Which of the following operations are correct?
A.
list.add("Red");
B.
list.add(new Integer(100));
C.
list.add(new java.util.Date());
D.
list.add(new ArrayList());A.
list.add(“Red”);
To declare a class named A with two generic types, use
B. public class A -E, F- (Brackets, no parenthesis)
To declare an interface named A with a generic type, use
A.
public interface A { ... }
B.
public interface A { ... }
C.
public interface A(E) { ... }
D.
public interface A(E, F) { ... }A.
public interface A -E- (Brackets, no parenthesis)
To declare an interface named A with two generic types, use
A.
public interface A { ... }
B.
public interface A { ... }
C.
public interface A(E) { ... }
D.
public interface A(E, F) { ... }B.
public interface A -E, F- (Brackets, no parenthesis)
To create a list to store integers, use
A. ArrayList list = new ArrayList<>(); B. ArrayList list = new ArrayList<>(); C. ArrayList list = new ArrayList(); D. ArrayList list = new ArrayList<>();
B.Integer (in brackets)
To create a generic type bounded by Number, use
A.E extends number
Which of the following declarations use raw type?
D. ArrayList list = new ArrayList();
If you use the javac command to compile a program that contains raw type, what would the compiler do?
A. report syntax error B. report warning and generate a class file C. report warning without generating a class file D. no error and generate a class file E. report warning and generate a class file if no other errors in the program.
E. report warning and generate a class file if no other errors in the program.
If you use the javac ?Xlint:unchecked command to compile a program that contains raw type, what would the compiler do?
A. report compile error B. report warning and generate a class file C. report warning without generating a class file D. no error and generate a class file
B. report warning and generate a class file
Is ArrayList a subclass of ArrayList? A. Yes B. No
B. No
Is ArrayList a subclass of ArrayList>? A. Yes B. No
A. Yes
Is ArrayList a subclass of ArrayList extends Number>? A. Yes B. No
A. Yes
Is ArrayList a subclass of ArrayList extends Number>? A. Yes B. No
A. Yes
Is ArrayList> same as ArrayList extends Object>?
A. Yes B. No
A. Yes
Does super Number> represent a superclass of Number?
A. Yes B. No
A. Yes
Which of the following can be used to replace YYYYYYYY in the following code?
publicclassWildCardDemo3{
publicstaticvoidmain(String[] args) {
GenericStack stack1 =newGenericStack<>();
GenericStack stack2 =newGenericStack<>();
stack2.push("Java");
stack2.push(2);
stack1.push("Sun");
add(stack1, stack2);
WildCardDemo2.print(stack2);
} publicstaticvoidadd(GenericStack stack1,
GenericStack stack2) {
while(!stack1.isEmpty())
stack2.push(stack1.pop());
}
}
A.
? super Object
B.
? super T
C.
? extends T
D.
? extends ObjectB.
? super T
ArrayList and ArrayList are two types. Does the JVM load two classes ArrayList and ArrayList?
A.
Yes
B.
No
B. No
If E is a generic type for a class, can E be referenced from a static method?
A. Yes B. No
B. No
Fill in the most appropriate code in the blanks in the MyInt class?
publicclassMyIntimplements_______{
intid;
publicMyInt(intid) {
this.id = id;
}
publicString toString() {
returnString.valueOf(id);
} publicintcompareTo(\_\_\_\_\_\_\_ arg0) {
if(id > arg0.id)
return1;
elseif(id < arg0.id)
return-1;
else
return0;
}
}
A.
Comparable / Object
B.
Comparable / MyInt
C.
Comparable / Object
D.
Comparable / MyIntB.
Comparable / MyInt
To declare a class named A with a generic type, use
public class A -E- (in brackets)