using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace InheritanceApp
{
class Employee
{
public void CalculatePay()
{
Console.WriteLine("Employee.CalculatePay()");
}
}
class SalariedEmployee : Employee
{
//如果去掉new出现如下警告
//警告:“InheritanceApp.SalariedEmployee.CalculatePay()”隐藏了继承的成员“InheritanceApp.Employee.CalculatePay()”。如果是有意隐藏,请使用关键字 new。
//new的作用:new方法都与基类中方法无关(与方法名称、原型、返回类型、修饰符方面都无关)
new public void CalculatePay()
{
Console.WriteLine("SalariedEmployee.CalculatePay()");
}
}
class Program
{
static void Main(string[] args)
{
Employee e = new Employee();
e.CalculatePay();
SalariedEmployee s = new SalariedEmployee();
s.CalculatePay();
Console.ReadKey();
}
}
}