If B is driven from A, then the following statement:
A a = new B()How many reference type values created on the managed heap, 1 or 2?Who know the answer, please help me and give your reason?

解决方案 »

  1.   

    2
    when create b,create a first,
    a is father of b.
      

  2.   

    If D:C, C:B, B:A, A gg = new D(), you mean 4 created according to your reason?
      

  3.   

    just one//just my opinion
      

  4.   

    1. wo kanbudong yingyu !
    2. buyao bishi wo!
      

  5.   

    测试一下就可以了。 继承关系上面,它的父类的构造函数肯定被调用    class Program
        {
            static void Main(string[] args)
            {
                A a = new D();
            }
        }    public class A
        {
            public A()
            {
                Console.WriteLine("A instance of A has been created!");
            }
        }    public class B:A
        {
            public B()
            {
                Console.WriteLine("A instance of B has been created!");
            }
        }    public class C:B
        {
            public C()
            {
                Console.WriteLine("A instance of C has been created!");
            }
        }    public class D:C
        {
            public D()
            {
                Console.WriteLine("A instance of D has been created!");
            }
        }
    输出为:A instance of A has been created!
    A instance of B has been created!
    A instance of C has been created!
    A instance of D has been created!
    Press any key to continue . . .
      

  6.   

    A a = new B();   
    首先构造的是B的父类的构造体,然后才是B的构造体
    override重写,是指对父类中的虚方法(标记virtual)或抽象方法(标记为abstract)进行重写