日期:2014-05-20 浏览次数:20923 次
import java.util.ArrayList; public class Vehicle { public void run(){ System.out.print("Vruum"); } public void stop(){ System.out.print("stop!"); } } class Car extends Vehicle{ public void run(){ System.out.print("Car vruum"); } public static void main (String... args){ ArrayList<Vehicle> cars = new ArrayList<Car>(); cars.run(); } }
import java.util.ArrayList; public class Vehicle { public void run(){ System.out.print("Vruum"); } public void stop(){ System.out.print("stop!"); } } class Car extends Vehicle{ public void run(){ System.out.print("Car vruum"); } public static void main (String... args){ //还有,这句话不报错吗?我的jdk1.5 ArrayList<Vehicle> cars = new ArrayList<Car>(); //cars.run(); //这句话出错把,应该改为 cars.add(new Car()); cars.get(0).run(); } }