Java OCA OCP Practice Question 2303

Question

Which statements can be inserted at (1) without the compiler reporting any errors?.

public class Main {
   public static void main(String[] args) {
      List lst = new ArrayList<String>();
       // (1) INSERT HERE
   }
}

Select the four correct answers.

  • (a) lst.add(null);
  • (b) lst.add("OK");
  • (c) lst.add(2007);
  • (d) String v1 = lst.get(0);
  • (e) Object v2 = lst.get(0);


(a), (b), (c), and (e)

Note

(a), (b) and (c) The compiler will report unchecked call warnings.

(d) Incompatible types, assigning type Object to type String.

(e) From any list, we are guaranteed to get an Object.




PreviousNext

Related