Egret 类的创建和继承

1class test extends egret.DisplayObjectContainer { 2 /** 3 * 类的创建 4 */ 5 //属性 6 name: string; 7 age: number; 8 ts: test; 9 //可传参的构造方法 10 public constructor(name: string, age: number) { 11 super(); 12 this.name = name; 13 this.age = age; 14 } 15 //普通函数 16 public print() { 17 return this.name + ":" + this.age; 18 } 19 public check() { 20 //使用:利用对象调用函数的执行 21 let tc = new test("sss", 12); 22 alert(tc.print()); 23 //2 24 25 } 26 27} 28let tc = new test("sss", 12); 29alert(tc.print()); 30/** 31 * 类的继承 32 */ 33class Person { 34 name: string; 35 age: number; 36 public constructor() { } 37 //普通函数 38 public print() { 39 return this.name + ":" + this.age; 40 } 41 public check() { 42 //使用 43 44 } 45} 46class Student extends Person { 47 school: string; 48 public print() { 49 return this.name + ":" + this.age + ":" + this.school; 50 } 51} 52//调用 53var s = new Student(); 54s.name = "ss"; 55s.age = 900; 56s.school = "aa"; 57alert(s.print()); 58//或者通过构造函数直接传参,就不需要对象做赋值操作 59//Person 60/* 61public constructor(name: string, age: number) { 62 this.name = name; 63 this.age = age; 64} 65//student 66public constructor(school:string) { 67 this.school = school; 68 super("aaa",100); 69}*/
点赞
收藏

评论区

加载中...

相关推荐

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

js继承的几种方式

1.原型链继承原型链继承:想要继承,就必须要提供父类(继承谁,提供继承的属性)//父级functionPerson(name)//给构造函数添加参数this.namename;this.age10;this.sumfunction()console.log(this.name)//原

java8新特性

Stream将List转换为Map,使用Collectors.toMap方法进行转换背景:User类,类中分别有id,name,age三个属性。List集合,userList,存储User对象1、指定keyvalue,value是对象中的某个属性值。 Map<Integer,StringuserMap1userList.str

java 中链表的实现

//数据类 class DATA2{String key;String name;int age;}//定义链表类class CLType{DATA2 nodedatanew DATA2();CLType nextNodenull;//下

你不可不知的JS面试题(第二期)

1、什么是继承?子类可以使用父类的所有功能,并且对功能进行扩展。新增方法改用方法(1)、ES6使用extends子类继承父类的方法。// 父类    class A        constructor(name)            this.name name;                getNa

Java类和对象

一、类类是封装对象的属性和行为的载体,在Java语言中对象的属性以成员变量的形式存在,而对象的方法以成员方法的形式存在。1\.类的构造方法构造方法是一个与类同名的方法,对象的创建就是通过构造方法完成的,构造方法分为有参构造方法和无参构造方法,区别就在于有没有参数。说这么多概念是不是感觉有点麻木,直接看下面的例子吧。pub