Consider the following code:
public class SubClass extends SuperClass{ int i, j, k; public SubClass ( int m, int n ) { i = m ; j = m ; } //1 public SubClass ( int m ) { super (m ); } //2 }
Which of the following constructors must exist in SuperClass for SubClass to compile correctly?
Select 2 options
Correct Options are : C D
For A.
The //2 will fail as it needs a constructor taking an int!
For B.
It is not used anywhere so it is not necessary.
For C.
Because it is called in the second constructor of SubClass.
For D.
The default no args constructor will not be provided because SuperClass has to define one arg constructor.
For E.
You'll have to explicitly define a no args constructor because it is needed in the first constructor of SubClass.