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

  • Home
  • SEARCH
  • 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 963969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:45:10+00:00 2026-05-16T01:45:10+00:00

In C# .NET, I have 2 concrete classes. Class A and B. Class B

  • 0

In C# .NET, I have 2 concrete classes. Class A and B. Class B is a subclass of Class A.

How many instances (objects on the heap) and references from the stack to the heap objects are created for each line of code:

  1. ClassB b = new ClassB();

  2. ClassA a = new ClassB();

  • 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-16T01:45:11+00:00Added an answer on May 16, 2026 at 1:45 am

    Going with the analogy that the object is a balloon and the reference is a string that is tied to the baloon, in each of the following cases there would be one balolon and one string:

    ClassB b = new ClassB(); //one reference, one heap object
    ClassA a = new ClassB(); //one reference, one heap object
    

    Running both at the same time will therefore create two objects and two references.

    EDIT Have a look at this IL generated from ClassB constructor:

    .method public hidebysig specialname rtspecialname 
            instance void  .ctor() cil managed
    {
      // Code size       7 (0x7)
      .maxstack  8
      IL_0000:  ldarg.0
      IL_0001:  call       instance void InheritanceTest.ClassA::.ctor()
      IL_0006:  ret
    } // end of method ClassB::.ctor
    

    call instance void InheritanceTest.ClassA::.ctor() indicates that it calls ClassA constructor as a member function(not as a function on a member object). This is in line with my understanding about what happens with instances of inherited classes, that the derived class is simply all the members of the base class, followed by members of its own, similarly to C++.

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

Sidebar

Related Questions

I have a dictionary of 10000 Product/Colour/Size combinations which I have created with something
I have .Net 2.0 Windows form containing combobxes. I have written following code to
Is there an equivalent library for JAXB in .NET? I am trying to convert
In Ninject there's automatic implicit self-binding for concrete types. So without further configuration I
I am currently trying to access a SonicWALL VPN , inside of a .NET
Is it possible to get WSDL.exe to generate interfaces as well as, or instead
I'm facing some architectural problems on the project I'm involved in. The project is
I'm in the process of designing the architecture of an application I’m planning on
Disclaimer Please don't just vote to close this because the title looks subjective, and
Are there any helpers that will transform/escape a string to be a valid XML

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.