大神来看看
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; } }
public class car extends Bus { //子类轿车类 public void showSeat(){ //方法重写 this.seat=4; System.out.println("子类car的座位数为"+seat); System.out.println("父类的Bus的座位数为"+super.seat); } public car(int seat){ //带参构造方法 super(seat); System.out.println("子类的构造方法"); } }
public class test { public static void main(String[] args){ car honda=new car(55); honda.showSeat(); } }
问下大神 为什么输出是:
子类car的座位数为4
父类的Bus的座位数为4
我只是在构造方法里面给seat赋了一个值55吧