zoukankan      html  css  js  c++  java
  • 接口和抽象类


    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 ");
            }



        }
       


  • 相关阅读:
    unity 颜色空间
    Shader 常用常量 函数等
    Unity3d cg Shader 相关的方法
    DirectX HLSL Shader 内置函数
    unity texture2d 图片尺寸压缩
    Unity中Zxing生成二维码只能生成256大小图片的解决方案
    读取保存 调用系统选框 仅限Win/Mac/WebGL
    Unity编辑器中递归设置文件夹下资源的 AssetBundle Tag 可多选
    扣绿幕Shader(可自选颜色)
    智能手环体验:UP24
  • 原文地址:https://www.cnblogs.com/duwamish/p/1513391.html
Copyright © 2011-2022 走看看