Beispiel #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("-------------虚函数调用---------------");
            Console.WriteLine("【L1 call  L3 instance】");
            L1 l = new L3();

            l.Func();
            Console.WriteLine(); Console.WriteLine();
            Console.WriteLine("【L2 call  L3 instance】");
            ((L2)l).Func();
            Console.WriteLine(); Console.WriteLine();
            Console.WriteLine("【L2 call  L3 instance】");
            L2 ll = new L3();

            ll.Func();
            Console.WriteLine(); Console.WriteLine();
            Console.WriteLine("【L1 call  L2 instance】");
            L1 lll = new L2();

            lll.Func();
            Console.WriteLine(); Console.WriteLine();
            Console.WriteLine("【L1 call  L1 instance】");
            L1 llll = new L1();

            llll.Func();
            Console.WriteLine("-----------------非虚函数调用--------------------");
            Console.Write("s1v2    ");
            L1 s1v2 = new L2();

            s1v2.Function();
            Console.Write("s2v2    ");
            L2 s2v2 = new L2();

            s2v2.Function();
            Console.Write("s1v3    ");
            L1 s1v3 = new L3();

            s1v3.Function();
            Console.Write("s2v3    ");
            L2 s2v3 = new L3();

            s2v3.Function();
            Console.Write("s3v3    ");
            L3 s3v3 = new L3();

            s3v3.Function();
        }
Beispiel #2
0
 static void Main(string[] args)
 {
     Console.WriteLine("-------------虚函数调用---------------");
     Console.WriteLine("【L1 call  L3 instance】");
     L1 l = new L3();
     l.Func();
     Console.WriteLine(); Console.WriteLine();
     Console.WriteLine("【L2 call  L3 instance】");
     ((L2)l).Func();
     Console.WriteLine(); Console.WriteLine();
     Console.WriteLine("【L2 call  L3 instance】");
     L2 ll = new L3();
     ll.Func();
     Console.WriteLine(); Console.WriteLine();
     Console.WriteLine("【L1 call  L2 instance】");
     L1 lll = new L2();
     lll.Func();
     Console.WriteLine(); Console.WriteLine();
     Console.WriteLine("【L1 call  L1 instance】");
     L1 llll = new L1();
     llll.Func();
     Console.WriteLine("-----------------非虚函数调用--------------------");
     Console.Write("s1v2    ");
     L1 s1v2 = new L2();
     s1v2.Function();
     Console.Write("s2v2    ");
     L2 s2v2 = new L2();
     s2v2.Function();
     Console.Write("s1v3    ");
     L1 s1v3 = new L3();
     s1v3.Function();
     Console.Write("s2v3    ");
     L2 s2v3 = new L3();
     s2v3.Function();
     Console.Write("s3v3    ");
     L3 s3v3 = new L3();
     s3v3.Function();
 }