Java OCA OCP Practice Question 59

Question

Consider the following class definition:

1. public class Test extends Base { 
2.   public Test(int j) { 
3.   } 
4.   public Test(int j, int k) { 
5.     super(j, k); 
6.   } 
7. } 

Which of the following are legitimate calls to construct instances of the Test class?

Choose all that apply.

  • A. Test t = new Test();
  • B. Test t = new Test(1);
  • C. Test t = new Test(1, 2);
  • D. Test t = new Test(1, 2, 3);
  • E. Test t = (new Base()).new Test(1);


B, C.

Note

Because the class has explicit constructors defined, the default constructor is suppressed, so A is not possible.

B and C have argument lists that match the constructors defined at lines 2 and 4 respectively, and so they are correct constructions.

D has three integer arguments, but there are no constructors that take three arguments of any kind in the Test class, so D is incorrect.

E is a syntax used for construction of inner classes and is therefore wrong.




PreviousNext

Related