酷代码 AI
菜单
服务商

Java 实战:汽车类继承车辆基类,实现属性扩展与方法重写

```java class Vehicle { private String brand; private double price; public Vehicle(String brand, double price) { this.brand = brand; this.price = price; } public void displayInfo() { System.out.println("Brand: " + brand); System.out.println("Price: $" + price); } } class Car extends Vehicle { private int numDoors; public Car(String brand, double price, int numDoors) { super(brand, price); this.numDoors = numDoors; } @Override public void displayInfo() { super.displayInfo(); System.out.println("Number of doors: " + numDoors); } public static void main(String[] args) { Car car = new Car("Toyota", 25000.0, 4); car.displayInfo(); } } ``` ######[AI问答 | 220点数解答 | 2025-04-15 14:38:26]

相关提问
本站限时免费提问中
实用工具查看更多
Linux在线手册 [开发类]
Jquery在线手册 [开发类]
今日油价 [生活类]
图片互转base64 [开发类]
时间转换器 [开发类]