C#子类与父类的初始化

    技术2022-05-11  17

    using System;class Field{    public Field(string str)    {        System.Console.WriteLine(str);    }}class Super{    private Field f = new Field("Super Field");    public Super()    {        System.Console.WriteLine("Super ctor");    }}class Sub:Super{    private Field f = new Field("Sub Field");    public Sub()    {        System.Console.Write("Sub ctor");    }}public class ClassInitTest{    public static void Main()    {        new Sub();    }}

    //结果  子类Field ->父类Field->父类构造函数->子类构造函,java好像不同


    最新回复(0)