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 trialDamir Demirovic
Courses Plus Student 446 PointsWhat is wrong here?
It's asking me to create object
public class Example {
public static void main(String[] args) {
System.out.println("We are going to create a GoKart");
GoKart.color = new GoKart();
}
}
2 Answers
Grigorij Schleifer
10,365 PointsHi damir,
delete the dot (.) after GoKart .... and dont forget to add the color parameter to the GoKart object ("Red").
The code should look like this:
GoKart goKart= new GoKart("Red");
// name the GoKart object, here goKart (not color)
// the color is your parameter that goes inside the parenthesis and needs " " because it is a String
// so the line means: create a GoKart object with the name goKart
// and give it a color parameter "Red" as a String
Makes sense?
Grigorij
Rune Andreas Nielsen
5,354 PointsHi Damir.
When you want to create an object, you need to first say object type in this case it is "GoKart". You did this right.
The next step is to give it a variable name, you didn't do it, but always remember to do that, i gave it "goKartVariable".
Third step is to new the object, you did this right. The task ask you to insert a color into the constructor of the object, you do that by putting a string "" into the (); I did put "Blue" as the string color.
ItΒ΄s very important that you DONT do this.
GoKart.color
Because you haven't created an object yet, so you wont be able to access itΒ΄s properties.
This is my solution:
public class Example {
public static void main(String[] args) {
System.out.println("We are going to create a GoKart");
GoKart goKartVariable = new GoKart("Blue");
}
}