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 trialChang Xu
3,248 PointsCreating object?
I don't really understand what this wants me to do... Do I have to create an entirely new GoKart and design it? What is the code it already displays?
public class Example {
public static void main(String[] args) {
System.out.println("We are going to create a GoKart");
}
}
2 Answers
Florian Tönjes
Full Stack JavaScript Techdegree Graduate 50,856 PointsYes, but you're still missing something. You have to tell the constructor which color the new GoKart should have.
Here is the GoKart class with it's constructor from the previous challenge:
public class GoKart {
private String mColor = "red";
// Constructor
public GoKart(String color) {
mColor = color;
}
public String getColor() {
return mColor;
}
}
Regards, Florian
Florian Tönjes
Full Stack JavaScript Techdegree Graduate 50,856 PointsHey Chang,
the challenge wants you to create a new instance of the 'GoKart' class that you had to design in the previous 'Constructors' challenge. The constructor takes a color as an argument that you pass in as a String.
Regards, Florian
Chang Xu
3,248 PointsSo using new as in GoKart goKart = new GoKart(); ?