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
    时间就像海绵里的水,只要你愿意挤,总还是有的——鲁迅
  • 相关阅读:
    为什么obj不等于obj?
    前端基础:深入理解内存空间
    微信小程序之富文本解析
    微信小程序加载更多 点击查看更多
    目前为止最全的微信小程序项目实例
    小程序图文列表一行俩列
    关于小程序 scroll-view 左右横向滑动没有效果(无法滑动)问题
    微信小程序商品筛选,侧方弹出动画选择页面
    小程序-带参跳转页面
    css-background-image 背景图片太大或太小
  • 原文地址:https://www.cnblogs.com/syzly/p/6659904.html
Copyright © 2011-2022 走看看