Does an instance of superclass get created when we instantiate a particular class in java. If that is the case then there would be a lot of overhead of instantiating all the
Yes.
BClass constructor looks like this:
public BClass ()
{
super (); // hidden line, added by compiler
System.out.println("Constructor B");
}
If you do not want to use default constructor, you can do like this:
public BClass ()
{
super (parameters); // now you will use different constructor from AClass
// compiler will not add here call to "super ()"
System.out.println("Constructor B");
}
From oracle site: If a constructor does not explicitly invoke a superclass constructor, the Java compiler automatically inserts a call to the no-argument constructor of the superclass. If the super class does not have a no-argument constructor, you will get a compile-time error. Object does have such a constructor, so if Object is the only superclass, there is no problem.