+ 1
What is the different between pointer "this" and this declaration
Vehicle() { this.setColor("Red"); } Vehicle() { setColor("Red"); }
1 Réponse
0
the difference is making the compiler work a little more to find out what object are you referring to
sometimes is a requirement to differentiate a parameter and an attribute with the same name
Vehicle (String color){
this.color = color;
}
the first one is referring to the attribute and the second one to the parameter
is advisable to write it to make it readable