zoukankan      html  css  js  c++  java
  • TypeScript笔记六

    /**
     * Created by ufo9631 on 2017/5/25.
     */
    class  Person{
        public  name; //不指定访问控制符默认是public
        //类被实例化的时候会被调用
        constructor(name:string){
            //console.log("哈哈");
         this.name=name;
        }
    
    /*  可以把属性名简写在构造函数里
        constructor(public name:string){
            //console.log("哈哈");
            this.name=name;
        }
    */
        //访问控制符 public,private ,protected
        eat()
        {
            console.log(name);
        }
    }
    
    //继承使用关键字extends
    //用super关键字调用父类方法
    class  Employee extends Person
    {
        code:string;
    
        constructor (name:string,code:string)
        {
            super(name);//子类的构造函数必须调用父类的构造函数
             this.code=code;
        }
        work(){
       super.eat();
        }
    }
    
    //实例化类
    var p1=new Person("batman");
    //p1.name="";
    p1.eat();
    
    var p2=new Person("supermane");
    p2.name="supermane";
    p2.eat();
    
    var e1=new Employee("继承","123");
    e1.eat();
    e1.code="123";
    

      

  • 相关阅读:
    论文笔记4
    论文笔记3
    论文笔记2
    论文笔记1
    论文笔记
    AFG与AWG的比较
    Linux下“有线线缆被拔出”问题的解决
    python生成excel格式座位表
    PythonTip--一马当先--bfs
    python pygame--倒计时
  • 原文地址:https://www.cnblogs.com/sumg/p/7841429.html
Copyright © 2011-2022 走看看