zoukankan      html  css  js  c++  java
  • C# 抽象类

     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 }
  • 相关阅读:
    ACM spiral grid
    ACM 数独
    Codeforces Round #242 (Div. 2) A. Squats
    Codeforces Round #242 (Div. 2) B. Megacity
    Codeforces Round #242 (Div. 2) C. Magic Formulas
    Coder-Strike 2014
    Coder-Strike 2014
    Coder-Strike 2014
    ACM Same binary weight
    C puzzles详解【13-15题】
  • 原文地址:https://www.cnblogs.com/thybk/p/7427111.html
Copyright © 2011-2022 走看看