Java OCA OCP Practice Question 3260

Question

Which constraint can be inserted at (1) so that the program compiles without warnings?

class NumClass <________________> { // (1)
  T numVal;/*from   w ww  .  j  a va 2s  .c o  m*/
}

public class Main {
   public static void main(String[] args) {
       NumClass<Number> n1 = new NumClass<Number>();
       NumClass<Integer> n2 = new NumClass<Integer>();
   }
}

Select the one correct answer.

  • (a) T extends Integer
  • (b) T extends Number
  • (c) ? extends Number
  • (d) T super Number
  • (e) T super Integer
  • (f) ? super Integer
  • (g) None of the above


(b)

Note

None of the formal type parameter specifications with a wildcard are permitted.

This rules out (c) and (f).

The keyword super can only be used with a wildcard, and therefore rules out (d) and (e).

NumClass<Number> is not a subtype of NumClass<T extends Integer>, ruling out (a).




PreviousNext

Related