58,454
社区成员
发帖
与我相关
我的任务
分享
public class Car {
private String busno;//车牌号
private int speed;//车速
private double weight;//载重量
public String getBusno() {
return busno;
}
public void setBusno(String busno) {
this.busno = busno;
}
public int getSpeed() {
return speed;
}
public void setSpeed(int speed) {
this.speed = speed;
}
public double getWeight() {
return weight;
}
public void setWeight(double weight) {
this.weight = weight;
}
@Override
public String toString() {
return "Car{" +
"busno='" + busno + '\'' +
", speed=" + speed +
", weight=" + weight +
'}';
}
/**
* 带参构造函数
* @param busno
* @param speed
* @param weight
*/
public Car(String busno, int speed, double weight) {
this.busno = busno;
this.speed = speed;
this.weight = weight;
}
/**
* 无参构造函数
*/
public Car() {
this.busno = "XX6666";
this.speed = 55;
this.weight = 777.77;
}
public static void main(String[] args) {
Car car1=new Car();//无参构造创建对象
car1.setBusno("YY8888");//
Car car2=new Car("ZZ9999",100,600);
System.out.println("car1==="+car1);
System.out.println("car2==="+car2);
}
}