+ 2

Constructor questions

https://code.sololearn.com/cj38ilikf5xd/?ref=app 1 This constuctor is also a setter too? Vehicle() { this.setColor("Red"); } 2 How does it know that the color attribute have to change when i create a new object?(if i have more attribute in the Vehicle class) Vehicle v2 = new Vehicle("Green");

22nd Mar 2018, 9:50 PM
Erik Horvath
Erik Horvath - avatar
3 Antworten
+ 1
thank you!
22nd Mar 2018, 10:32 PM
Erik Horvath
Erik Horvath - avatar
0
thank you! But if i have more attributes: Vehicle() { color = "red"; } Vehicle() { color2 = "blue"; } Vehicle(String color){ this.color = color; Vehicle(String color2){ this.color2 = color2; } Vehicle v2 = new Vehicle("Green");
22nd Mar 2018, 10:13 PM
Erik Horvath
Erik Horvath - avatar
0
thank you! But I have : Vehicle v2 = new Vehicle("Green"); Which will be alter color or color2?
22nd Mar 2018, 10:22 PM
Erik Horvath
Erik Horvath - avatar