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

in .net I have created an excel report which takes a datagrid's render output
I have a concrete class that contains a collection of another concrete class. I
Does .net have a way to determine whether the local filesystem is case-sensitive?
Does Visual Studio .NET have a way to toggle word-wrap on and off? I
Does dot net have an interface like IEnumerable with a count property? I know
If I have .Net Form with a component/object such as a textbox that I
In .NET I have already tried the configuration below successfully: <system.net> <connectionManagement> <add address=*
Does ASP.NET MVC have anything like the RESTful out-of-the-box features like Ruby on Rails
Does anyone here use VB.NET and have a strong preference for or against using
Is there anyway to have items in an ASP.NET DropDownList have either their Text

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.