示例#1
0
        static void Main(string[] args)
        {
            KDerived d = new KDerived();

            d.Start();
            d.Update();
            KBase b = new KDerived();

            b.Start();
            b.Update();
            KBase c = new KFinal();

            c.Start();
            c.Update();
            Console.ReadKey();

            /*
             *  KDerived::Start
             *  KBase::Update
             *  KDerived::Update
             *  KBase::Start
             *  KBase::Update
             *  KDerived::Update
             */
        }
        static void Main(string[] args)
        {
            KBase b = new KDerived();

            b.Start();
            b.Update();
            Console.ReadKey();

            /*
             *  KDerived::Start
             *  KDerived::Update
             */
        }
示例#3
0
    static void Main()
    {
        dynamic o1 = new KDerived();
        KBase   o2 = new KDerived();

        o1.Start();  // calls Start() of actual type
        o2.Start();  // calls Start() of variable type

        o1.Update(); // Update() is virtual function, so there is no difference with below
        o2.Update();

        /*  output:
         *  KDerived::Start
         *  KBase::Start
         *  KDerived::Update
         *  KDerived::Update
         */
    }