Self Quiz 4

Java’s generic programming does not apply to the primitive types. True or False?

Select one:

True Correct
False

The correct answer is 'True'.



Question 2

Which of the following statements is correct?

Select one or more:

a. Generics can help detect type errors at compile time, thus make programs more robust.
b. Generics can make programs easy to read.
c. Generics can avoid cumbersome castings.
d. Generics can make programs run faster.

The correct answer is: Generics can help detect type errors at compile time, thus make programs more robust., Generics can make programs easy to read., Generics can avoid cumbersome castings.



Question 3

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

a. <String>
b. <?>
c. <Date>
d. <E>

The correct answer is: c.



Question 4

Suppose List list = new ArrayList(). Which of the following operations are correct?

Select one or more:

a. list.add("Red"); 
b. list.add(new Integer(100));
c. list.add(new java.util.Date());
d. list.add(new ArrayList());

The correct answer is: list.add("Red");, list.add(new Integer(100));, list.add(new java.util.Date());, list.add(new ArrayList());



Question 5

Suppose List<String> list = new ArrayList<String>. Which of the following operations are correct?

Select one:

a. list.add("Red"); 
b. list.add(new Integer(100));
c. list.add(new java.util.Date());
d. list.add(new ArrayList());

The correct answer is: list.add("Red");



Question 6

In what way can a Set be distinguished from other types of Collections?
“A Set cannot contain duplicate elements.”

Select one:
True 
False

The correct answer is 'True'.



Question 7

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

a. public class A<E> { ... }
b. public class A<E, F> { ... }
c. public class A(E) { ... }
d. public class A(E, F) { ... }

The correct answer is: a.



Question 8

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

a. public class A<E> { ... }
b. public class A<E, F> { ... }
c. public class A(E) { ... }
d. public class A(E, F) { ... }

The correct answer is: b.


Question 9

To declare an interface named A with two generic types, use

a. public interface A<E> { ... }
b. public interface A<E, F> { ... }
c. public interface A(E) { ... }
d. public interface A(E, F) { ... }

The correct answer is: b.



Question 10

To create a list to store integers, use

a. ArrayList<Object> list = new ArrayList<Integer>();
b. ArrayList<Integer> list = new ArrayList<Integer>();
c. ArrayList<int> list = new ArrayList<int>();
d. ArrayList<Number> list = new ArrayList<Integer>();

The correct answer is: b.



No comments:

Post a Comment