Java OCA OCP Practice Question 2326

Question

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

public class Main {
   public static void main(String[] args) {
   //  (1) INSERT DECLARATIONS HERE
   }/*from  w ww.j ava 2s .  co  m*/

   public static <E extends Number> List<E> justDoIt(List<? super E> nums) {

    return null;
  }
}

Select the three correct answers.

(a) ArrayList<Integer> inParam = new ArrayList<Integer>();
    ArrayList<Integer> returnValue = justDoIt(inParam);

(b) ArrayList<Integer> inParam = new ArrayList<Integer>();
    List<Integer> returnValue = justDoIt(inParam);

(c) ArrayList<Integer> inParam = new ArrayList<Integer>();
    List<Number> returnValue = justDoIt(inParam);

(d) List<Number> inParam = new ArrayList<Number>();
    ArrayList<Integer> returnValue = justDoIt(inParam);

(e) List<Number> inParam = new ArrayList<Number>();
    List<Number> returnValue = justDoIt(inParam);

(f) List<Integer> inParam = new ArrayList<Integer>();
    List<Integer> returnValue = justDoIt(inParam);


(b) , (e), and (f)

Note

(a) and (d) Incompatible types for assignment: cannot convert from List<Integer> to ArrayList<Integer>.

(c) Incompatible types for assignment: cannot convert from List<Integer> to List<Number>.




PreviousNext

Related