Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help needed

 
arivu mathi
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please use tags.
Please use a meaningful topic title.
What output does it give? Explain what you do not understand about it.
 
sachinb mahajan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
wise owen
Ranch Hand
Posts: 2023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Constructor
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic