Java 2

Which of the following statements is correct?

A. Comparable<String> c = new String("abc");
B. Comparable<String> c = "abc";
C. Comparable<String> c = new Date();
D. Comparable<Object> c = new Date();





Suppose ArrayList<Double>list = new ArrayList<>(). Which of the following statements are correct?

A. list.add(5.5); // 5.5 is automatically converted to new Double(5.5)
B. list.add(3.0); // 3.0 is automatically converted to new Double(3.0)
C. Double doubleObject = list.get(0); // No casting is needed
D. double d = list.get(1); // Automatically converted to double



The method header is left blank in the following code. Fill in the header.

public class GenericMethodDemo {
  public static void main(String[] args ) {
    Integer[] integers = {1, 2, 3, 4, 5};
    String[] strings = {"London", "Paris", "New York", "Austin"};

    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)


To create a generic type bounded by Number, use
A. <E extends Number>
B. <E extends Object>
C. <E>
D. <E extends Integer>



Which of the following declarations use raw type?

A. ArrayList<Object> list = new ArrayList<Object>(); 
B. ArrayList<String> list = new ArrayList<String>(); 
C. ArrayList<Integer> list = new ArrayList<Integer>(); 
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.


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





No comments:

Post a Comment