public class Test extends A{ Test(){ System.out.println("Sub"); } public static void main(String args[]) { Test t = new Test(); } } class A{ A(int i){ System.out.println("Super"); } }
plz explain the output
Barry Gaunt
Ranch Hand
Joined: Aug 03, 2002
Posts: 7729
posted
0
Please use tags. Please use a meaningful topic title. What output does it give? Explain what you do not understand about it.
It wont give any output. Code wont get compiled. The Base class A has a constructor which takes int as an argument. Any class extending it has to have a constructor which will explicitly call base class constructor
else compiler will put default no arg super call in the derived class constructor which will cause the compilation to fail.