public class A
    {
        public   void fun()
        {
            Console.WriteLine("A");
        }        public virtual void fun2()
        {
            Console.WriteLine("A 2");
        }
    }    public class B:A
    {
        public void fun()//    警告 1“ConsoleApplication1.B.fun()”隐藏了继承的成员“ConsoleApplication1.A.fun()”。如果是有意隐藏,请使用关键字 new。
        {
            Console.WriteLine("B");
        }        public override void fun2()
        {
            //base.fun2();
            Console.WriteLine("B 2");
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            A a = new B() ;
            a.fun();
            a.fun2();
            B b = new B();
            b.fun();
            b.fun2();
            Console.Read();
        }
    }输出:
A
B 2
B
B 2通过上面的例子,可以看出在重写方法和普通方法之间的区别,如果是重写的方法,采用哪个方法是根据实例化的对象来决定,而不跟申明的对象有关系,但在普通方法里只跟申明的对象有关,与实例化的对象无关。而在B类的普通方法中,报了一个警告,这里有一个疑惑:
既然不用声明关键字new也是默认隐藏父类方法,那为什么还要用new声明呢,而且从例子中我们也看出,不论隐藏不隐藏父类方法,它的输出只根据声明对象有关,那这里所讲的隐藏父类方法又有什么意义?既然系统本身就自动屏蔽了父类方法,还为什么要显示声明new关键字?