public class Animal { static string baseClassName; protected string _skincolor; Instancevariable iv = new Instancevariable("父类实例成员变量"); static Instancevariable siv = new Instancevariable("父类静态成员变量"); static Animal() { baseClassName = "父类静态构造函数"; Console.WriteLine(baseClassName); } public Animal() { _skincolor = "父类构造函数"; Console.WriteLine(_skincolor); } } public class Instancevariable { public Instancevariable(string cls) { Console.WriteLine(cls); } } public class Horse : Animal { static string horseClassName; Instancevariable iv = new Instancevariable("子类实例成员变量"); static Instancevariable siv = new Instancevariable("子类静态成员变量"); public Horse() : base() { _skincolor = "子类类构造函数"; Console.WriteLine(this._skincolor); } static Horse() { horseClassName = "子类静态构造函数"; Console.WriteLine(horseClassName); } } class Program { static void Main(string[] args) { Horse h = new Horse(); Console.ReadLine(); } }
时间: 2024-11-06 18:38:29