Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7248701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:10:28+00:00 2026-05-28T22:10:28+00:00

Does an instance of superclass get created when we instantiate a particular class in

  • 0

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 super classes. I tried following code:

public class AClass {
    public AClass() {
        System.out.println("Constructor A");
    }
}

public class BClass extends AClass{
    public BClass(){
        System.out.println("Constructor B");
    }
}

public class Test {
    public static void main(String[] args) {
        BClass b = new BClass();
    }
}

The output of the code is :

Constructor A

Constructor B

So, does it mean that the complete hierarchy of the objects of the superclasses get created when we instantiate a class?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T22:10:28+00:00Added an answer on May 28, 2026 at 10:10 pm

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

1.Does dynamic proxy instance subclass the target class? The java doc says the proxy
The Question: When you UnicastRemoteObject.exportObject(instance) . Does that instance now become publicly available to
Why does defining __getitem__ on a class make it iterable? For instance if I
How many bytes of data does a typical HTTP get request consume. For instance
Why Microsoft.Practices.ServiceLocation.IServiceLocator does not offer TryGetInstance()? I need to get generic validator instance ServiceLocator.Current.GetInstance<IEntityValidator<TEntity>>()
When writing an abstract class, or a class that doesn't get instantiated directly... do
Why does Java specify that the access specifier for an overriding method can allow
I am trying this in an XQuery (assume that doc('input:instance') does indeed return a
Using class table inheritance it is recommended that the subclass refers to the superclass
Is there a way in java or scala, that allows to override methods of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.