对象继承3-重写父类
// es6 实现继承
class Phone{
// 构造方法
constructor(brand,price){
this.brand = brand;
this.price = price;
}
// 父类 成员属性
call(){
console.log('可以打电话');
}
}
// 智能手机
class SmartPhone extends Phone {
// 构造方法
constructor(brand,price,color,size){
super(brand,price); // Phone.call(this,brand,price);
this.color = color;
this.size = size;
}
// 声明子类的方法
photo(){
console.log('我可以拍照');
}
playGame(){
console.log('我可以玩游戏');
}
call(){
console.log('可以视频通话');
}
}
const chuizi = new SmartPhone('锤子',2499,'黑色','5.5inch');
console.log(chuizi);
chuizi.call(); // 可以视频通话
chuizi.photo();
chuizi.playGame();
我是Eric,手机号是13522679763

浙公网安备 33010602011771号