接口

来源:互联网 发布:矩阵关联分析法excel 编辑:程序博客网 时间:2024/05/16 08:25

namespace ConsoleApplication7
{
    interface Company
    {
        void onDuty();//接口的主题部分如果是方法则一定是公共抽象的,public abstract void onDuty();=void onDuty();
        void offDuty();
    }
    class Employee : Company
    {
        public void onDuty()
        {
            Console.WriteLine("都在上班");
        }
        public void offDuty()
        {
            Console.WriteLine("都下班了");
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Employee employee=new Employee();
            employee.onDuty();
            employee.offDuty();
            Console.Read();

        }
    }
}

//实现多个接口继承类

namespace ConsoleApplication9
{
    abstract class Person
    {
        public void eat()
        {
            Console.WriteLine("person is eating!");
        }
        public abstract void breathe();
    }
    interface Company
    {
        void onDuty();
        void offDuty();
    }
    class Employee : Person, Company
    {
        public void onDuty()
        {
            Console.WriteLine("is onduty!");
        }
        public void offDuty()
        {
            Console.WriteLine("is offduty!");
        }
        public override void breathe()
        {
            Console.WriteLine("is breathing!");
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Employee employee = new Employee();
            employee.onDuty();
            employee.offDuty();
            employee.breathe();
            Console.Read();
        }
    }
}

原创粉丝点击