Java OCA OCP Practice Question 2721

Question

Which of the following lines can be inserted to make the code compile? (Choose all that apply.)

class A {} //from  ww  w .  ja va  2s  .c om

class B extends A {} 

class C extends B {} 

class D<C> { 

   // INSERT CODE HERE 

} 
  • A. A a1 = new A();
  • B. A a2 = new B();
  • C. A a3 = new C();
  • D. C c1 = new A();
  • E. C c2 = new B();
  • F. C c1 = new C();


A, B.

Note

C is both a class and a type parameter.

This means that within the class D, when we refer to C, it uses the type parameter.

All of the choices that mention class C are incorrect because it no longer means the class C.




PreviousNext

Related