29.继承7.0.html 899 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. </head>
  8. <body>
  9. <script>
  10. class Vase {
  11. constructor(name) {
  12. this.name = name;
  13. }
  14. music() {
  15. console.log("音乐课");
  16. }
  17. }
  18. class Year extends Vase {
  19. constructor(name,age) {
  20. super(name);
  21. this.age = age;
  22. }
  23. sport() {
  24. console.log("运动");
  25. }
  26. static run() {
  27. console.log("跑步")
  28. }
  29. }
  30. let a1 = new Vase("小明");
  31. let a2 = new Year("小红",18);
  32. console.log(a1,'a1');
  33. console.log(a2,'a2');
  34. console.log(Year.run());
  35. </script>
  36. </body>
  37. </html>