Click here to Skip to main content
15,921,905 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
class A
{
    public A()
    {
        Console.WriteLine("Default A");
    }

    public A(int a)
    {
        Console.WriteLine("Parameterized A");
    }
}

class B : A
{
    public B()
    {
        Console.WriteLine("Default B");
    }

    public B(int a)
    {
        Console.WriteLine("Parameterized B");
    }
}


What I have tried:

How much memory will allocate if we call:

A a = new B();

and

A a = new A();
Posted
Updated 2-Nov-17 6:01am

1 solution

The same for both: the memory allocation is the fields the class contains (plus a class type identifier) not the actual methods the class contains. One copy of those is all that exists, and that's in your code, not on the heap or stack.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900