12345678910111213141516171819202122232425262728 |
- (function() {
- /***
- * 抽象类 与其他类差别不大
- * abstract
- * 抽象类不是为了实例化对象
- * 他是因为要继承而产生的
- */
- abstract class Animal {
- name:string;
- constructor(name:string) {
- this.name = name;
- }
- // 只能定义方法体
- abstract say():void;
- // say() {
- // console.log("你好啊")
- // }
- }
-
- class Dog extends Animal {
- say() {
- console.log("我叫"+this.name)
- }
- }
- let dog1 = new Dog('旺财a');
- console.log(dog1,'dog1')
- dog1.say()
- })()
|