zoukankan      html  css  js  c++  java
  • 接口 Interface

    1.interface 关键字 声明接口;

    2.接口中的成员默认都是public 也不能加“访问修饰符”,只要一个类继承了这个接口,就必须实现这个接口中的所有成员;

    3.接口中只能有方法,属性,索引器,事件,不能有“字段”和 构造函数;

    4.接口和接口之间可以继承,并且可以多继承;接口不能继承类,类可以继承接口

    5.当虚方法继承接口时,需子类去实现;

    6.能力不一样的时候适合用接口;

    using System;
    using System.Collections;
    using System.Collections.Generic;
    namespace Dome
    {
        class dom
        {
            static void Main(string[] args)
            {
                play iplay = new student();
                iplay.iplay();
                Console.WriteLine();
                Console.ReadKey();
            }
        }
        public class person {//父类
            public void sayhello() { Console.WriteLine("我是人类"); }
        }
        public class student:person,play {//继承父类person和接口play  必须实现接口中的成员
            public void hello() { Console.WriteLine("我是学生"); }
            public void iplay() { Console.WriteLine("实现接口"); }
        }
        interface play {//接口中的成员默认是public
            void iplay();
        }
    }
     
    View Code

     显示实现接口

    using System;
    using System.Collections;
    using System.Collections.Generic;
    namespace Dome
    {
        class dom
        {
            static void Main(string[] args)
            {
                play iplay = new person();
                iplay.iplay();
                person p = new person();
                p.iplay();
                Console.ReadKey();
            }
        }
        public class person:play {
    
            void play.iplay()//显示实现接口
            {
                Console.WriteLine("我是接口中的方法");
            }
            public void iplay() //类中的方法
            { Console.WriteLine("我是类中的方法"); }
        }
       
        interface play {//接口中的成员默认是public
            void iplay();
        }
    }
     
    View Code
    时间就像海绵里的水,只要你愿意挤,总还是有的——鲁迅
  • 相关阅读:
    Java中判断两个列表是否相等
    chrome:插件、跨域、调试....
    mac 开发环境采坑
    webpack升级踩坑
    js-使用装饰器去抖
    React setState 笔试题,下面的代码输出什么?
    react 解决:容器组件更新,导致内容组件重绘
    centos使用ngnix代理https
    javascript 理解继承
    js 数据监听--对象的变化
  • 原文地址:https://www.cnblogs.com/syzly/p/6659904.html
Copyright © 2011-2022 走看看