以下是使用 Java 实现上述需求的代码: ```java class Vehicles { String brand; String color; // 构造方法 public Vehicles(String brand, String color) { this.brand = brand; this.color = color; } public void run() { System.out.println("我已经开动了"); } public void showInfo() { System.out.println("商标: " + brand + ", 颜色: " + color); } } class Car extends Vehicles { int seats; // 构造方法 public Car(String brand, String color, int seats) { super(brand, color); this.seats = seats; } public void showCar() { System.out.println("小汽车商标: " + brand + ", 颜色: " + color + ", 座位数: " + seats); } } public class Main { public static void main(String[] args) { Vehicles vehicle = new Vehicles("丰田", "白色"); vehicle.run(); vehicle.showInfo(); Car car = new Car("宝马", "黑色", 5); car.run(); car.showInfo(); car.showCar(); } } ``` [2024-09-18 21:39:01 | AI写代码神器 | 290点数解答]