using System;
using System.Collections.Generic;public class Father
{
    public  void hand()
    {
        Console.WriteLine("Father.hand");
    }
}public class Son : Father
{
    public new void hand()
    {
        Console.WriteLine("Son.hand");
    }
    static void Main(string[] args)
    {
        Father son = new Son();
        son.hand();
        Console.ReadLine();
    }
}这个是吧基类中的hand() 隐藏了吧,在Son 类中,,,,,,,运行结果是Father.hand    why?

解决方案 »

  1.   

    你把new 换成override比较一下就知道了
      

  2.   

    new 用作修饰符时,new关键字可以在派生类中隐藏基类的方法
      

  3.   

    Override关键字主要是提供派生类对基类方法的新实现,重写的基类方法必须和Override的方法具有相同的签名
    New关键字主要用来区别派生类和基类同名方法的选择问题,通过隐藏基类方法,达到使编译器调用正确的方法的目的。Override主要用来对基类的方法和虚方法进行重写
      

  4.   

    new 用作修饰符时,new关键字可以在派生类中隐藏基类的方法   对的,,,,那结果应该是 Son.hand ,,怎么会是father.hand ?
    override 是把重写,,,这个是对的。
      

  5.   

    Father son = new Son();
    调用哪个hand()是根据定义的类型来确定,而不是根据实际对象来确定申明的Father,所以调用的就是Father类的hand()方法