package com.imooc3;
public class Bus {
int seat;//座位数
float price;
public void showSeat(){
this.seat=47;
System.out.println("Bus的座位数为:"+seat);
}
public Bus(int seat){
System.out.println("父类的构造方法");
this.seat=seat;
}
package com.imooc3;
public class Car extends Bus {
public void showSeat(){ //方法重写
System.out.println("父类的Bus的座位数为"+super.seat);
int seat=4;
System.out.println("子类car的座位数为"+this.seat); //为什么用this.seat和super.seat输出的值是一样的呢
System.out.println("父类的Bus的座位数为"+super.seat);
}
public Car(int seat){ //带参构造方法
super(seat);
System.out.println("子类的构造方法");
}
}
package com.imooc3;
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
Car honda=new Car(55);
honda.showSeat();
}
}
最后结果是:
父类的构造方法
子类的构造方法
父类的Bus的座位数为55
子类car的座位数为55
父类的Bus的座位数为55
chavin
相关分类