创建一个车辆类,数据成员有,重量,型号,函数成员有:显示车辆信息,还需要
答案:1 悬赏:70 手机版
解决时间 2021-02-05 05:41
- 提问者网友:情歌越听越心酸
- 2021-02-04 10:12
创建一个车辆类,数据成员有,重量,型号,函数成员有:显示车辆信息,还需要
最佳答案
- 五星知识达人网友:神鬼未生
- 2021-02-04 10:39
package test;
public class Vehicle {
private float weight;
private String type;
public float getWeight() {
return weight;
}
public void setWeight(float weight) {
this.weight = weight;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public Vehicle() {
}
public Vehicle(float weight,String type) {
this.weight = weight;
this.type = type;
}
public void showVehileInfo(){
System.out.println(this.toString());
}
@Override
public String toString() {
return "Vehicle [weight=" + weight + ", type=" + type+ "]";
}
public static void main(String[] args) {
new Vehicle().showVehileInfo();
new Vehicle(123.1F,"xxx-xxx").showVehileInfo();
}
}
public class Vehicle {
private float weight;
private String type;
public float getWeight() {
return weight;
}
public void setWeight(float weight) {
this.weight = weight;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public Vehicle() {
}
public Vehicle(float weight,String type) {
this.weight = weight;
this.type = type;
}
public void showVehileInfo(){
System.out.println(this.toString());
}
@Override
public String toString() {
return "Vehicle [weight=" + weight + ", type=" + type+ "]";
}
public static void main(String[] args) {
new Vehicle().showVehileInfo();
new Vehicle(123.1F,"xxx-xxx").showVehileInfo();
}
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯