Example #1
0
        public static void Hiding_Methods()
        {
            Derive2 d2  = new Derive2();
            Base    bd2 = new Derive2();

            Console.WriteLine(d2.noVirtualMethod());                // 输出 Derive2 No virtual method
            Console.WriteLine(d2.VirtualMethod());                  // 输出 Derive2 virtual method
            Console.WriteLine(bd2.noVirtualMethod());               // 输出 Base No virtual method
            Console.WriteLine(bd2.VirtualMethod());                 // 输出 Derive2 virtual method

            Derive3 d3  = new Derive3();
            Derive4 d4  = new Derive4();
            Base    bd3 = new Derive3();
            Base    bd4 = new Derive4();
            Derive3 dd3 = new Derive4();

            Console.WriteLine(d3.noVirtualMethod());                // 输出 Base No virtual method
            Console.WriteLine(d3.VirtualMethod());                  // 输出 Derive3 virtual method
            Console.WriteLine(d4.noVirtualMethod());                // 输出 Base No virtual method
            Console.WriteLine(d4.VirtualMethod());                  // 输出 Derive4 virtual method
            Console.WriteLine(bd3.noVirtualMethod());               // 输出 Base No virtual method
            Console.WriteLine(bd3.VirtualMethod());                 // 输出 Base virtual method
            Console.WriteLine(bd4.noVirtualMethod());               // 输出 Base No virtual method
            Console.WriteLine(bd4.VirtualMethod());                 // 输出 Base virtual method
            Console.WriteLine(dd3.noVirtualMethod());               // 输出 Base No virtual method
            Console.WriteLine(dd3.VirtualMethod());                 // 输出 Derive4 virtual method

            Base bd5 = new Derive5();

            Console.WriteLine(bd5.noVirtualMethod());               // 输出 Base No virtual method
            Console.WriteLine(bd5.VirtualMethod());                 // 输出 Derive1 virtual method
        }
Example #2
0
        public static void Hiding_Methods()
        {
            Derive2 d2 = new Derive2();
            Base bd2 = new Derive2();

            Console.WriteLine(d2.noVirtualMethod());                // 输出 Derive2 No virtual method
            Console.WriteLine(d2.VirtualMethod());                  // 输出 Derive2 virtual method
            Console.WriteLine(bd2.noVirtualMethod());               // 输出 Base No virtual method
            Console.WriteLine(bd2.VirtualMethod());                 // 输出 Derive2 virtual method

            Derive3 d3 = new Derive3();
            Derive4 d4 = new Derive4();
            Base bd3 = new Derive3();
            Base bd4 = new Derive4();
            Derive3 dd3 = new Derive4();

            Console.WriteLine(d3.noVirtualMethod());                // 输出 Base No virtual method
            Console.WriteLine(d3.VirtualMethod());                  // 输出 Derive3 virtual method
            Console.WriteLine(d4.noVirtualMethod());                // 输出 Base No virtual method
            Console.WriteLine(d4.VirtualMethod());                  // 输出 Derive4 virtual method
            Console.WriteLine(bd3.noVirtualMethod());               // 输出 Base No virtual method
            Console.WriteLine(bd3.VirtualMethod());                 // 输出 Base virtual method
            Console.WriteLine(bd4.noVirtualMethod());               // 输出 Base No virtual method
            Console.WriteLine(bd4.VirtualMethod());                 // 输出 Base virtual method
            Console.WriteLine(dd3.noVirtualMethod());               // 输出 Base No virtual method
            Console.WriteLine(dd3.VirtualMethod());                 // 输出 Derive4 virtual method

            Base bd5 = new Derive5();
            Console.WriteLine(bd5.noVirtualMethod());               // 输出 Base No virtual method
            Console.WriteLine(bd5.VirtualMethod());                 // 输出 Derive1 virtual method
        }