• Post Reply Bookmark Topic Watch Topic
  • New Topic

implicit call to super  RSS feed

 
abhijeet kush
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator




As far as i know that implicit call to super is made through subclass constructor (correct me if i am wrong).Then from where the super is called even though bike class dont have construtor.
 
Puspender Tanwar
Ranch Hand
Posts: 499
2
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java implicitly provides the default constructor if we don't provide it manually. And in a constructor is the top most statement and it must be when we provide it manually. If a class is not having a super class then also its constructor will have in it which will point to the constructor of the class which is the so called father of all the class.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, if your subclass constructor does not explicitly call a superclass constructor, then the compiler will automatically add a super(); call as the first thing in the subclass's constructor.

And a different rule is: if a class does not have a constructor, then the compiler automatically adds a no-arguments constructor. Ofcourse, the rule above about super(); is also applied to that automatically created constructor.

So this:

is exactly the same as this:

 
Sachin Tripathi
Ranch Hand
Posts: 368
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As it is a rule of oop's:
Compiler searches for constructor in a class if it cant find one it places a default constructor which is non paramaterised and whose first line is
super();
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sachin Tripathi wrote:As it is a rule of oop's:
Compiler searches for constructor in a class if it cant find one it places a default constructor which is non paramaterised and whose first line is
super();

That rule is specific to the Java programming language, and is not a general rule in object-oriented programming (OOP). Other object-oriented programming languages may not work in the same way as Java.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!