现在的位置: 首页 > 综合 > 正文

类接口的作用。

2013年01月26日 ⁄ 综合 ⁄ 共 578字 ⁄ 字号 评论关闭
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace ConsoleApplication1
{
    class China : Walkable
    {
        public void Walk()
        {
            Console.WriteLine("人走路");
        }
    }


    class Dog : Walkable
    {
        public void Walk()
        {
            Console.WriteLine("狗走路");
        }
    }


    class Bird : FLyable, Walkable
    {
        public void Fly()
        {
            Console.WriteLine("飞起来了");
        }


        public void Walk()
        {
            Console.WriteLine("鸟在路上走");
        }
    }


    interface FLyable//接口只能定义能干什么,但是不能定义出来怎么干。
    {
        void Fly();
    }


    interface Walkable
    {
        void Walk();
    }
    class Program
    {
        static void Main(string[] args)
        {
            Bird b = new Bird();
            b.Fly();
            b.Walk();
            China c = new China();
            c.Walk();
            Dog d = new Dog();
            d.Walk();
            Console.ReadKey();
        }
    }
}
【上篇】
【下篇】

抱歉!评论已关闭.