zoukankan      html  css  js  c++  java
  • typescript-class-interface

    interface Human {
        // new (name:string):void;  //不能约束类的构造函数
        name:string;
        eat():void;
    }
    
    class Asian implements Human {
        constructor(name:string){   //接口也不能约束类的构造函数
            this.name = name
        }
        name:string;
        // private name:string;    //接口不能约束类的私有属性
        eat(){}
        sleep(){}
    }
    /**
     * 接口只能约束类的公有成员
     */
    
    //  接口继承接口
     interface  Man extends Human{
         run():void
     }
    
     interface Child {
         cry():void
     }
    
     interface Boy extends Man,Child {}
    
     let boy:Boy = {
         name:'',
         run(){},
         eat(){},
         cry(){}
     }
    
    //  接口继承类: 接口把类的成员都抽象了出来  有类的结构 但没有具体实现
     class Auto {
         state =  1
        //  private state2 = 0  
     }
     interface AutoInterface extends Auto {}
     
     class C implements AutoInterface {
         state = 2  
        //  c不是子类  所以private属性无法实现 报错
     }
     class Bus extends Auto implements AutoInterface {
        // 因为是Auto的子类 , 已经继承了state  就不用再实现了  
        // 注意:  接口在抽离类的成员的时候,不仅抽离了公共成员, 还有私有成员和受保护成员
     }
    

  • 相关阅读:
    java并发5-volatile关键字解析
    java并发4-单例设计方法
    Java并发3-多线程面试题
    JAVA并发2
    JAVA并发
    2015第27周三Java内存模型
    同一时候使用windows和linux系统
    深入浅出Windows BATCH
    DrawText的使用
    redmine忘记username和password
  • 原文地址:https://www.cnblogs.com/chengyunshen/p/12857208.html
Copyright © 2011-2022 走看看