java学校上学期的题,谁能给个参考答案

img

代码如下:


public class Car {

    private String brand;
    private String version;
    private int hoursePower;
    public String getBrand() {
        return brand;
    }
    public void setBrand(String brand) {
        this.brand = brand;
    }
    public String getVersion() {
        return version;
    }
    public void setVersion(String version) {
        this.version = version;
    }
    public int getHoursePower() {
        return hoursePower;
    }
    public void setHoursePower(int hoursePower) {
        this.hoursePower = hoursePower;
    }
    
    void display(){
        System.out.println(brand + " " + version + " " + hoursePower);
    }
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Car c1 = new Car();
        c1.setBrand("BYD");
        c1.setVersion("Tang");
        c1.setHoursePower(200);
        c1.display();
    }

}

这是JAVA的基础题,方法的重载,封装等基础练习。

/**
 * @author zhouzh6
 * @date 2021-07-05
 */
public class Car {
    private String brand;
    private String version;
    private String horsePower;

    public static void main(String[] args) {
        Car car = new Car("红旗", "H9", "600牛米");
        car.disPlay();
    }

    public String disPlay() {
        return "Car{" +
                "brand='" + brand + '\'' +
                ", version='" + version + '\'' +
                ", horsePower='" + horsePower + '\'' +
                '}';
    }

    public Car(String brand, String version, String horsePower) {
        this.brand = brand;
        this.version = version;
        this.horsePower = horsePower;
    }

    public String getBrand() {
        return brand;
    }

    public void setBrand(String brand) {
        this.brand = brand;
    }

    public String getVersion() {
        return version;
    }

    public void setVersion(String version) {
        this.version = version;
    }

    public String getHorsePower() {
        return horsePower;
    }

    public void setHorsePower(String horsePower) {
        this.horsePower = horsePower;
    }
}