Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialcasey bova
Courses Plus Student 1,541 PointsI need help with add a constructor
I need help with challenge task 3 of 3 in add a constructor I am having trouble I would like to understand thise
public class GoKart {
public String color = "red";
public GoKart(String color) {
this.Color = color;
}
public String getColor () {
return = Color;
}
}
1 Answer
Mihai Craciun
13,520 Pointsthe third question asked you to remove the initialization from the field definition so you just have to remove the "red" parameter from String color = "red";
This is because when you will create an object which type is GoKart you will already pass a color parameter so there is no point to declare it in object
The code should be look like this:
class GoKart {
private String color;
public GoKart(String color){
this.color = color;
}
public String getColor() {
return color;
}
}