//父类
class Person {
constructor(name, age) {
this.name = name
this.age = age
}
printInfo() {
console.log(this.name)
console.log(this.age)
}
}
//字类
class Student extends Person {
constructor(name, age, major) {
// this.name = name
// this.age = age
//调用父类的构造函数
super(name, age)
this.major = major
}
//定义在字类自身的原型对象上
study() {
console.log("好好学习")
}
//定义在字类自身的原型对象上
//方法的覆盖、重写
printInfo() {
// console.log(this.name)
// console.log(this.age)
//调用父类的printInfo
super.printInfo()
console.log(this.major)
}
}
let s1 = new Student("tom", 18, "IT")
console.log(s1.name, s1.age, s1.major)
//调用父类的继承来的方法
s1.printInfo()
//调用字类自身的方法
s1.study()
console.log(s1)