I know that both chunks of code work but as I am trying to understand the use of "this" I would really appreciate it if you could explain me why the class Vehicle1 is 'better' than Vehicle2. Thanks a lot in advance!
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;
}
}