Generics
Generics
19.4 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());
Check Answer for Question 4
print(integers);
print(strings);
}
__________________________________________ {
for (int i = 0; i < list.length; i++)
System.out.print(list[i] + " ");
System.out.println();
}
}
A. public static void print(Integer[] list)
B. public static void print(String[] list)
C. public static void print(int[] list)
D. public static void print(Object[] list)
E. public static <E> void print(E[] list)
Check Answer for Question 12
19.15 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.
Check Answer for Question 15
19.16 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
Check Answer for Question 16
19.23 Which of the following can be used to replace YYYYYYYY in the following
code?
19.24 Which of the following can be used to replace YYYYYYYY in the following
code?
19.27 If E is a generic type for a class, can E be referenced from a static method?
A. Yes
B. No
Check Answer for Question 27
19.28 Fill in the most appropriate code in the blanks in the MyInt class?