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();

        }
    }

   
}
继承(四):new方法都与基类中方法无关

相关文章:

  • 2021-06-06
  • 2022-12-23
  • 2022-03-05
  • 2021-12-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-05
猜你喜欢
  • 2022-12-23
  • 2021-05-26
  • 2022-02-13
  • 2021-07-27
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案