以下是使用 Java 实现上述需求的代码: ```java class Vehicles { String brand; String color; // 构造方法初始化成员属性 Vehicles(String brand, String color) { this.brand = brand; this.color = color; } // 行驶方法 void run() { System.out.println("我已经开动了"); } // 显示信息方法 void showInfo() { System.out.println("商标: " + brand + ", 颜色: " + color); } } class Car extends Vehicles { int seats; // 构造方法 Car(String brand, String color, int seats) { super(brand, color); this.seats = seats; } // 显示小汽车信息的方法 void showCar() { showInfo(); System.out.println("座位数: " + seats); } } public class Main { public static void main(String[] args) { Vehicles vehicle = new Vehicles("Toyota", "White"); vehicle.run(); vehicle.showInfo(); Car car = new Car("BMW", "Black", 5); car.run(); car.showCar(); } } ``` [2024-09-18 21:36:23 | AI写代码神器 | 293点数解答]