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 trialStevan Popov
Courses Plus Student 421 PointsPrint out using System.out.printf the color of the new object, using the getColor method. Pleas help.
I get error at GoKart color = new GoKart(); ^
public class Example {
public static void main(String[] args) {
System.out.println("We are going to create a GoKart");
GoKart color = new GoKart ("red");
System.out.printf("New Gokart is %s\n", color.getColor());
}
public class GoKart {
private String mColor;
public GoKart (String color) {
mColor = color;
}
public String getColor() {
return mColor;
}
}
}
1 Answer
Gloria Dwomoh
13,116 PointsHi there Stevan Popov , the reason why it points that error is this
GoKart color = new GoKart ("red");
there is a space after GoKart that shouldn't be there. So that needs to change to...
GoKart color = new GoKart("red");
In addition to that the extra classes you added below were not asked from you so you might like to remove that from there. According to the java language specification, there can be only one public class in a file and the file name should be the same as the public class name. So you can't put two public classes in the same file as that will give you an error of its own and if you check the editor it will be stating " error: class GoKart is public, should be declared in a file named GoKart.java public class GoKart {" so you definitely should remove the GoKart class and your issues will be solved :)
Stevan Popov
Courses Plus Student 421 PointsStevan Popov
Courses Plus Student 421 PointsThanks gloria , but how do i make getColor method if i can't make a new file like in video?
Gloria Dwomoh
13,116 PointsGloria Dwomoh
13,116 PointsYou are welcome. I believe that is already coded behind the scenes. That happens in several code challenges. If you were in another editor or in workspaces you'll need to create that class in another file for it to run though, but in this code challenge it is not asked for.
Stevan Popov
Courses Plus Student 421 PointsStevan Popov
Courses Plus Student 421 PointsOmg i did not know that thanks so much. xD
Gloria Dwomoh
13,116 PointsGloria Dwomoh
13,116 PointsHa ha, it's all right, now you know. You are welcome Stevan.