To answer this question, we need to understand the concepts of constructors and inheritance in Java.
In the given code, there are two classes: base
and Super
. The Super
class extends the base
class.
The base
class has two constructors:
- The default constructor
base()
which prints "base".
- The parameterized constructor
base(int i1)
.
The Super
class has one constructor Super()
. Inside this constructor, the super()
statement is used to invoke the default constructor of the base
class.
In the main
method, an object b1
is created using the new
keyword. The object is of type base
and is assigned as a reference to the Super
class.
Now, let's go through each option to determine the correct answer:
Option A) Compile time error - This option is correct. When the Super
class extends the base
class, it inherits the default constructor of the base
class. However, when a class has a parameterized constructor and the default constructor is not explicitly defined, the default constructor is no longer available. In this case, the base
class does not have an explicit default constructor, so the super()
statement in the Super
class constructor will result in a compile-time error.
Option B) Prints base and super - This option is incorrect because the code will not compile, and hence, nothing will be printed.
Option C) Prints super and base - This option is incorrect because the code will not compile, and hence, nothing will be printed.
Option D) None of the above - This option is incorrect because the code will not compile, and hence, nothing will be printed.
Therefore, the correct answer is A) Compile time error.