C# 虚方法 复习

什么是 overide 方法, vertual ,abstract的设计意义是什么,话不多说看 实验代码:

 public class Test2 {
            public void M1() {
                Console.WriteLine("Test2.M1");
            }
            public virtual void M2() {
                Console.WriteLine("Test2.M2");
            }
        }
        public class Test22:Test2 {
            public override void M2() {
                Console.WriteLine("Test22.M2");
            }
        }
        public class Test23:Test2 {
            new public void M1() {
                Console.WriteLine("Test33.M1");
            }
        }
        [TestMethod]
        public void m24() {
            Test2 t22=new Test22();
            Test2 t23=new Test23();
            t22.M2();
            t23.M1();
        }

猜你喜欢

转载自www.cnblogs.com/ProjectDD/p/11320623.html