Does an instance of superclass get created when we instantiate an object?

Solution 1:

A single object is created - but that object is an instance of both the superclass and the subclass (and java.lang.Object itself). There aren't three separate objects. There's one object with one set of fields (basically the union of all the fields declared up and down the hierarchy) and one object header.

The constructors are executed all the way up the inheritance hierarchy - but the this reference will be the same for all of those constructors; they're all contributing to the initialization of the single object.

Solution 2:

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.

Solution 3:

Yes, that's the whole point of class inheritance.

You're not instantiating two objects, though: you're instantiating one object, and running both the AClass and then the BClass constructor on it. The AClass constructor is responsible for initializing the parts that were inherited from AClass, and the BClass constructor is responsible for initializing the additional things defined in BClass.