Java OCA OCP Practice Question 2297

Question

Which statements are true about the following code?.

public class Main {
  public static void main(String[] args) {
    List legacyList = new ArrayList<Integer>(); // (1)
    List<?> anyList = legacyList;               // (2)
    legacyList = anyList;                        // (3)
  }
}

Select the one correct answer.

  • (a) The compiler will report errors in the code.
  • (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 without unchecked warnings.


(e)

Note

Any generic list can be assigned to a raw list reference.

A raw list and an unbounded wildcard list are assignment compatible.




PreviousNext

Related