10
0

5.抽象类.ts 635 B

12345678910111213141516171819202122232425262728
  1. (function() {
  2. /***
  3. * 抽象类 与其他类差别不大
  4. * abstract
  5. * 抽象类不是为了实例化对象
  6. * 他是因为要继承而产生的
  7. */
  8. abstract class Animal {
  9. name:string;
  10. constructor(name:string) {
  11. this.name = name;
  12. }
  13. // 只能定义方法体
  14. abstract say():void;
  15. // say() {
  16. // console.log("你好啊")
  17. // }
  18. }
  19. class Dog extends Animal {
  20. say() {
  21. console.log("我叫"+this.name)
  22. }
  23. }
  24. let dog1 = new Dog('旺财a');
  25. console.log(dog1,'dog1')
  26. dog1.say()
  27. })()