• 接口和抽象类



    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Collections;
    using System.Collections.Specialized;
    using System.Threading;
    using Arrayfds;
    using System.Reflection;

    namespace TestArray
    {
        
    class Program
        {
            
    static void Main(string[] args)
            {
                Animal duck 
    = new Duck("Duck");
                duck.MakeVoice();
                duck.Show();


                Animal dog 
    = new Dog("Dog");
                dog.MakeVoice();
                dog.Show();


                IAction dogAction 
    = new Dog("A big dog");
                dogAction.Move();


                Console.ReadLine();
            }

        }




        
    abstract public class Animal
        {
            
    protected string _name;

            
    public abstract string Name
            {
                
    get;
            }

            
    //声明抽象方法
            public abstract void Show();


            
    public void MakeVoice()
            {
                Console.WriteLine(
    "all animals can make voice");
            }

        }

        
    public interface IAction
        {
            
    //定义公共方法标签
            void Move();
        }


        
    public class Duck : Animal, IAction
        {
            
    public Duck(string name)
            {
                _name 
    = name;
            }

            
    //重载抽象方法
            public override void Show()
            {
                Console.WriteLine(_name 
    + " is showing for you.");
            }

            
    //重载抽象属性
            public override string Name
            {
                
    get { return _name; }
            }

            
    //实现接口方法
            public void Move()
            {
                Console.WriteLine(
    "Duck also can swim.");
            }

        }



        
    public class Dog : Animal, IAction
        {
            
    public Dog(string name)
            {
                
    this._name = name;
            }

            
    public override void Show()
            {

                Console.WriteLine(
    this._name + " is showing for you.");
            }

            
    public override string Name
            {
                
    get { return _name; }
            }


            
    public void Move()
            {
                Console.WriteLine(_name 
    + "also can run ");
            }



        }
       


  • 相关阅读:
    Jenkins安装以及邮件配置
    TUXEDO管理命令总结
    QTP的退出函数
    QTP 启动应用软件方法
    Robot framework 和RIDE 关系
    使用pycharm编写和运行RF脚本
    刷题-力扣-102. 二叉树的层序遍历
    刷题-力扣-反转链表
    刷题-牛客-判断链表中是否有环
    刷题-力扣-278. 第一个错误的版本
  • 原文地址:https://www.cnblogs.com/duwamish/p/1513391.html
Copyright © 2020-2023  润新知