码迷,mamicode.com
首页 > Windows程序 > 详细

C# 抽象类

时间:2017-08-25 12:32:18      阅读:135      评论:0      收藏:0      [点我收藏+]

标签:pac   ace   bst   cat   方法   ide   key   over   sum   

 

 1 namespace ConsoleApplication2
 2 {
 3     class Program
 4     {
 5         static void Main(string[] args)
 6         {
 7            Football footBall =new Football();
 8            BasketBall basketBall=new BasketBall();
 9            //调用PlayBall方法
10            PlayBall(footBall);
11            PlayBall(basketBall);
12             Console.ReadKey();
13         }
14 
15         static void PlayBall(Ball ball)
16         {
17             Console.WriteLine("球类:{0}",ball.Ballname);
18             ball.Play();
19         }
20     }
21 
22     public abstract class Ball
23     {
24         /// <summary>
25         /// 球的名字
26         /// </summary>
27         public abstract string Ballname { get; }
28 
29         /// <summary>
30         /// 打球
31         /// </summary>
32         public abstract void Play();
33     }
34 
35     public class Football :Ball
36     {
37         public override string Ballname
38         {
39             get { return "足球"; }
40         }
41 
42         public override void Play()
43         {
44             Console.WriteLine("正在踢足球...");
45         }
46     }
47     public class BasketBall : Ball
48     {
49         public override string Ballname
50         {
51             get { return "篮球"; }
52         }
53 
54         public override void Play()
55         {
56             Console.WriteLine("正在打篮球...");
57         }
58     }
59 }

 

C# 抽象类

标签:pac   ace   bst   cat   方法   ide   key   over   sum   

原文地址:http://www.cnblogs.com/thybk/p/7427111.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!