示例#1
0
        static void Main(string[] args)
        {
            // The Principal class will ouput
            // 'Monitor' since the variable
            // 'g' is the simply declared as a
            // new Princpal() class.
            Principal g = new Principal();

            g.Monitor();

            // d will return 'Monitor' as it
            // is a child class of the Principal
            // so it will inherit the base
            // function. At the same time, it
            // can call its own function when
            // used in d.Teach().
            Teacher d = new Teacher();

            d.Monitor();
            d.Teach();

            // The student class is another
            // child class of Principal. It
            // contains its own unique function
            // printing out 'Learn' while
            // retaining Principal's 'Monitor'
            // and thus will be able to call it
            // when used in dot notation.
            Student s = new Student();

            s.Monitor();
            s.Learn();
            Console.ReadKey();
        }
示例#2
0
        static void Main(string[] args)
        {
            Principal g = new Principal();

            g.Monitor();
            Teacher d = new Teacher();

            d.Monitor();
            d.Teach();
            Student s = new Student();

            s.Monitor();
            s.Learn();
            Console.ReadKey();
        }