C#多态(二)

View Code
 1  public class studyMutils
 2  {
 3      public static void Main()
 4      {
 5          People p = new Student();
 6          p.Watch();
 7          p.Read();
 8      }
 9  }
10  public class People
11  {
12     
13      public void Say()
14     {
15       Console.WriteLine("今天好累啊");     
16      }
17      public virtual void Watch()
18     {
19       Console.WriteLine("我喜欢看动画片");     
20      }
21       public virtual void Read()
22     {
23          
24       Console.WriteLine("我喜欢读读者");
25      }
26  }
27  public class Teacher : People
28  {
29      public void Run()
30     {
31           Console.WriteLine("hello");
32      }
33       public override void Watch()
34     {
35       Console.WriteLine("我喜欢看武侠片");     
36      }
37      public override void Read()
38     {
39          
40       Console.WriteLine("我喜欢读哲学");
41      }
42  }
43  public class Student : Teacher
44  {
45      public  override void Watch()
46     {
47       Console.WriteLine("我喜欢看警匪片");
48      }
49     
50  }

 

posted @ 2012-08-04 14:51  妍珊  阅读(287)  评论(0编辑  收藏  举报