Java OCA OCP Practice Question 2344

Question

Which declaration statement is not valid in the code below?

class Main<V> {
      Main()         {System.out.println(this);}               // (1)
  <T> Main(T t)      {System.out.println(t);}                  // (2)
  <T> Main(T t, V v) {System.out.println(t + ", " + v);}       // (3)
}

Select the one correct answer.

  • (a) Main<String> ref1 = new Main<String>();
  • (b) Main<String> ref2 = new Main<String>("one");
  • (c) Main<String> ref3 = new Main<String>(2007);
  • (d) Main<String> ref4 = new <Integer>Main<String>(2007);
  • (e) Main<String> ref5 = new <String>Main<String>("one");
  • (f) Main<String> ref6 = new Main<String>(2007, "one");
  • (g) Main<String> ref7 = new <Integer>Main<String>(2007, "one");
  • (h) Main<String> ref8 = new <Integer>Main<String>("one", 2007);


(h)

Note

(a) Invokes the default constructor at (1).

(b) Invokes the constructor at (2) with T as String and V as String.

(c) Invokes the constructor at (2) with T as Integer and V as String.

(d) Invokes the constructor at (2) with T as Integer and V as Integer.

(e) Invokes the constructor at (2) with T as String and V as String, same as (b).

(f) Invokes the constructor at (3) with T as Integer and V as String.

The constructor requires parameters (Integer, String), which is compatible with the arguments (Integer, String) in the constructor call.

(g) Invokes the constructor at (3) with T as Integer and V as String, same as (f).

(h) T is Integer and V is String.

The constructor requires parameters (Integer, String), which is not compatible with the arguments (String, Integer) in the constructor call.




PreviousNext

Related