Chapter 19 Flashcards

1
Q

Fill in the code in Comparable______ c = new Date();

A

C.Date

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

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

A.

list.add(“Red”);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

To declare a class named A with two generic types, use

A
B.
public class A -E, F- (Brackets, no parenthesis)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
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

A.

public interface A -E- (Brackets, no parenthesis)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
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) { ... }
A

B.

public interface A -E, F- (Brackets, no parenthesis)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

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<>();
A

B.Integer (in brackets)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

To create a generic type bounded by Number, use

A

A.E extends number

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Which of the following declarations use raw type?

A
D.
ArrayList list = new ArrayList();
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

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.
A
E.
report warning and generate a class file if no other errors in the program.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

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
A
B.
report warning and generate a class file
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
Is ArrayList a subclass of ArrayList?
		A.
Yes
		B.
No
A

B. No

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q
Is ArrayList a subclass of ArrayList>?
		A.
Yes
		B.
No
A

A. Yes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q
Is ArrayList a subclass of ArrayList extends Number>?
		A.
Yes
		B.
No
A

A. Yes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q
Is ArrayList a subclass of ArrayList extends Number>?
		A.
Yes
		B.
No
A

A. Yes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Is ArrayList> same as ArrayList extends Object>?

	A. Yes
	B. No
A

A. Yes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Does super Number> represent a superclass of Number?

	A. Yes
	B. No
A

A. Yes

17
Q

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 Object
A

B.

? super T

18
Q

ArrayList and ArrayList are two types. Does the JVM load two classes ArrayList and ArrayList?

A.
Yes
B.
No

A

B. No

19
Q

If E is a generic type for a class, can E be referenced from a static method?

	A. Yes
	B. No
A

B. No

20
Q

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 / MyInt
A

B.

Comparable / MyInt

21
Q

To declare a class named A with a generic type, use

A

public class A -E- (in brackets)