C#中base的作用

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _05base关键字
{

//显示的调用父类的构造函数
//调用父类中的重名方法
class Program
{
static void Main(string[] args)
{
Student s = new Student();
Console.ReadKey();
}
}
public class Person
{
public void Test()
{
Console.WriteLine("我是父类");
}
}
public class Student:Person
{
public /*new*/ void Test()//new在子类中隐藏父类继承过来的方法
{
base.Test();
Console.WriteLine("我是子类");
}
}
}

猜你喜欢

转载自www.cnblogs.com/tsh292278/p/9023753.html