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?
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?
when create b,create a first,
a is father of b.
2. buyao bishi wo!
{
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 . . .
首先构造的是B的父类的构造体,然后才是B的构造体
override重写,是指对父类中的虚方法(标记virtual)或抽象方法(标记为abstract)进行重写