Java OCA OCP Practice Question 2293

Question

What will be the result of attempting to compile the following code?.

public class Main {
  public static void main(String[] args) {
    List<Integer> glst1 = new ArrayList();       //(1)
    List nglst1 = glst1;                         //(2)
    List nglst2 = nglst1;                        //(3)
    List<Integer> glst2 = glst1;                 //(4)
  }
}

Select the one correct answer.

  • (a) The code will compile without any warnings.
  • (b) The code will compile with an unchecked warning in (1).
  • (c) The code will compile with an unchecked warning in (2).
  • (d) The code will compile with an unchecked warning in (3).
  • (e) The code will compile with an unchecked warning in (4).


(b)

Note

The compiler issues an unchecked conversion warning in (1), as we are assigning a raw list to a generic list.




PreviousNext

Related