gpt4 book ai didi

java - 用这个。在 java

转载 作者:行者123 更新时间:2023-11-29 04:28:50 25 4
gpt4 key购买 nike

<分区>

我知道这两个代码块都可以工作,但是当我试图理解“this”的用法时,如果您能解释一下为什么 Vehicle1 类比 Vehicle2 类“更好”,我将不胜感激。非常感谢!

public class Vehicle1 {
private String color;

Vehicle(String c) {
this.setVehicle(c);
}
Vehicle() {
this.setVehicle("Red");;
}
public void setVehicle(String c) {
this.color = c;
}
public String getVehicle() {
return color;
}
}


public class Vehicle2 {
private String color;

Vehicle(String c) {
color = c;
}
Vehicle() {
color = "Red";
}
public String getVehicle() {
return color;
}
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com