请大神求解obj1.way()为什么会报错
public class Vehicles { //父类
public static void main(String[] args) {
Vehicles obj1 = new Vehicles();
Vehicles obj2 = new Bus();
Vehicles obj3 = new boat();
Vehicles obj4 = new airplane();
obj1.way();
}}
}
public class Bus extends Vehicles { //子类BUS
int number=50;
String name="bus";
String function="陆地";
public void way() {
System.out.println("载客"+number+"人的"+name+"是在"+function+"上运行的");
}
}
public class boat extends Vehicles { //子类BUS
int number=500;
String name="boat";
String function="海洋";
public void way() {
System.out.println("载客"+number+"人的"+name+"是在"+function+"上运行的");
}
}
public class airplane extends Vehicles { //子类airplane
int number=1000;
String name="airplant";
String function="天空";
void way() {
System.out.println("载客"+number+"人的"+name+"是在"+function+"上运行的");
}
}