共回答了20个问题采纳率:100%
第一题 :
import java.util.ArrayList;
import java.util.List;
class Vehicle {
public void run(){
System.out.println("这是交通工具run方法");
}
}
class Motor extends Vehicle{
public void run(){
System.out.println("这是Motorrun方法");
}
}
class Ship extends Vehicle{
public void run(){
System.out.println("这是Shiprun方法");
}
}
class Aeroplane extends Vehicle{
public void run(){
System.out.println("这是Aeroplanerun方法");
}
}
class Car extends Motor{
public void run(){
System.out.println("这是Carrun方法");
}
}
class Bus extends Motor{
public void run(){
System.out.println("这是Busrun方法");
}
}
public class Test{
public static void main(String[] args) {
List list=new ArrayList();
Vehicle v1=new Vehicle();
Vehicle v2=new Motor();
Vehicle v3=new Ship();
Vehicle v4=new Aeroplane();
Vehicle v5=new Car();
Vehicle v6=new Bus();
list.add(v1);
list.add(v2);
list.add(v3);
list.add(v4);
list.add(v5);
list.add(v6);
for (Vehicle vehicle : list) {
vehicle.run();
}
}
}
1年前
4