子类继承父类,重写父类,在子类中调用父类被覆盖的方法。
public class Person { public virtual void GetInfo()//要标明是什么函数;virtual虚函数 { Console.WriteLine("qqqqqqqe"); } } class Employee:Person { public override void GetInfo() { base.GetInfo(); Console.WriteLine("11111"); } public void Info() { base.GetInfo(); } } class Program { static void Main(string[] args) { Employee e = new Employee(); e.Info(); Console.WriteLine("-----------"); e.GetInfo(); Console.ReadLine(); } }
子类的构造函数实例化是调用父类的构造函数
public class Person { public Person() { Console.WriteLine("1234"); } public Person(int i) { Console.WriteLine($"编号:{i}"); } } class Employee:Person { public Employee() : base() { } public Employee(int i) : base(i) { Console.WriteLine(i); } } class Program { static void Main(string[] args) { Employee e = new Employee(); Employee em = new Employee(1); Console.ReadLine(); } }
标签:Console,Person,base,WriteLine,Employee,public From: https://www.cnblogs.com/lin-07/p/17550455.html