Question
class Base
{
Base()
{
System.out.print("Base");
}
}
public class Alpha extends Base
{
public static void main(String[] args)
{
new Alpha(); /* Line 12 */
new Base(); /* Line 13 */
}
}
What will be the output of the program?
class Base
{
Base()
{
System.out.print("Base");
}
}
public class Alpha extends Base
{
public static void main(String[] args)
{
new Alpha(); /* Line 12 */
new Base(); /* Line 13 */
}
}
Answer: Option B
Was this answer helpful ?
Option B is correct. It would be correct if the code had compiled, and the subclass
Alpha had been saved in its own file. In this case Java supplies an implicit call from
the sub-class constructor to the no-args constructor of the super-class therefore line
12 causes Base to be output. Line 13 also causes Base to be output.
Option A is wrong. It would be correct if either the main class or the subclass had not
been instantiated.
Option C is wrong. The code compiles.
Option D is wrong. There is output.
Was this answer helpful ?
More Questions on This Topic :
Question 10.
Which two cause a compiler error? 1. float....
Submit Solution