C#高阶语法—继承、多态、IO、委托

  • 命名空间中的类的访问修饰符是什么? 

 static void Main(string[] args)
        {

            //能调用student,证明student不是private。实际上,命名空间类的类默认是internal
            Student s = new Student();
            s.Run();//能继承父类中的方法,说明student也不是private

            //run执行的是Person中的方法,说明没有重写.
            //new只是隐藏了父类中的方法,
            Person p = new Student();
            p.Run();

            Console.ReadKey();
        }

        class Person
        {
            public void Run()
            {
                Console.WriteLine("Person can run");
            }
        }

        class Student:Person
        {
            public new void Run()
            {
                Console.WriteLine("Student can run");
            }
        }
View Code

 

posted @ 2021-05-24 20:14  wesley1680  阅读(45)  评论(0编辑  收藏  举报