Java school last semester's question, who can give a reference answer

CSDN Q & A 2022-02-13 07:30:29 阅读数:433

java school semester question reference

img




Take the answer :

The code is as follows :

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(); }}


Other answers 2:

This is a JAVA The basic question of , Method overloading , Basic exercises such as packaging .


Other answers 3:
/** * @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(" The red flag ", "H9", "600 Cattle meters "); 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; }}
copyright:author[CSDN Q & A],Please bring the original link to reprint, thank you. https://en.javamana.com/2022/02/202202130730278751.html