java Vehicle 类作为父类,属性有 string engine 和 int wheelNum,使用的方法有 void run()和 void stop()。Car类为子类,属性有 boole
oad(num:int):void。
Vehicle类的代码如下:
```java
public class Vehicle {
private String engine;
private int wheelNum;
public Vehicle(String engine, int wheelNum) {
this.engine = engine;
this.wheelNum = wheelNum;
}
public void run() {
System.out.println("Vehicle is running.");
}
public void stop() {
System.out.println("Vehicle has stopped.");
}
}
```
Car类的代码如下:
```java
public class Car extends Vehicle {
private boolean openable;
public Car(String engine, int wheelNum, boolean openable) {
super(engine, wheelNum);
this.openable = openable;
}
public void getIn(int num) {
System.out.println(num + " people get in the car.");
}
public void getOut(int num) {
System.out.println(num + " people get out of the car.");
}
}
```
Truck类的代码如下:
```java
public class Truck extends Vehicle {
private int capacity;
public Truck(String engine, int wheelNum, int capacity) {
super(engine, wheelNum);
this.capacity = capacity;
}
public void load(int num) {
System.out.println("Load " + num + " goods.");
}
public void unload(int num) {
System.out.println("Unload " + num + " goods.");
}
}
```
以上是Vehicle、Car和Truck类的基本代码,可以根据需要进行扩展和修改。
Vehicle类的代码如下:
```java
public class Vehicle {
private String engine;
private int wheelNum;
public Vehicle(String engine, int wheelNum) {
this.engine = engine;
this.wheelNum = wheelNum;
}
public void run() {
System.out.println("Vehicle is running.");
}
public void stop() {
System.out.println("Vehicle has stopped.");
}
}
```
Car类的代码如下:
```java
public class Car extends Vehicle {
private boolean openable;
public Car(String engine, int wheelNum, boolean openable) {
super(engine, wheelNum);
this.openable = openable;
}
public void getIn(int num) {
System.out.println(num + " people get in the car.");
}
public void getOut(int num) {
System.out.println(num + " people get out of the car.");
}
}
```
Truck类的代码如下:
```java
public class Truck extends Vehicle {
private int capacity;
public Truck(String engine, int wheelNum, int capacity) {
super(engine, wheelNum);
this.capacity = capacity;
}
public void load(int num) {
System.out.println("Load " + num + " goods.");
}
public void unload(int num) {
System.out.println("Unload " + num + " goods.");
}
}
```
以上是Vehicle、Car和Truck类的基本代码,可以根据需要进行扩展和修改。