Search code examples
c#inheritanceinstances

Base class instance in inheritance


Hope I'm not asking something that has been already answered in here.

If my class B inherits from class A, does new B() create two instances in heap where B instance contains pointer to A instance, or there will be created only one instance of B including A members?


Solution

  • From Microsoft Inheritance article :

    This is how an object is represented in memory, given the Class Publication directly inherits the class Object.

    enter image description here

    So a inherited class is an object that contains all information about itself but also about its base class.