public class Traffic {
public int people;
public String location;
@Override
public String toString() {
return "Traffic [people=" + people + ", location=" + location + "]";
}
}
public class Bus extends Traffic {
public int people = 40;
public String location = "陆地"; //重写属性
@Override
public String toString() {
return "Bus [people=" + people + ", location=" + location + "]";
}
}
public class Initial {
public static void main(String[] args) {
Traffic tra1 = new Bus();
System.out.println(tra1); //输出Bus [people=40, location=陆地]
System.out.println(tra1.people);//输出0,为什么不是40?成员变量不能重载?
}
}