接口小练习

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 接口小练习
{
    class Program
    {
        static void Main(string[] args)
        {
            ///什么时候用虚方法实现多态?
            ///什么时候用抽象类实现多态?
            ///什么时候用接口来实现多态?
            ///

            ///真的鸭子会游泳,木头鸭子不会游泳,橡皮鸭子会游泳
            ISwimming duck = new RealDuck();
            duck.Swim();
            Console.ReadKey();
            
        }
    }
    public class RealDuck:ISwimming
    {
        public void Swim()
        {
            Console.WriteLine("我是真鸭子,会游泳");
        }
    }
    public class MuDuck : ISwimming
    {
        public void Swim()
        {
            Console .WriteLine ("我是木头鸭子,不会游泳");
        }
    }
    public class XpDuck : ISwimming
    {
        public void Swim()
        {
            Console .WriteLine ("我是橡皮鸭子,也会游泳");
        }
    }
    public interface ISwimming
    {
        void Swim();
    }
}

 

posted @ 2021-08-11 20:05  静态类  阅读(29)  评论(0编辑  收藏  举报