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 trialabdur rafay
1,933 PointsCode is compiling but tree house is giving an error.
this is the code for the exercise
public class Example {
public static void main(String[] args) {
System.out.println("We are going to create a GoKart");
Example GoKart = new Example();
}
}
its compiling and giving the correct output, but treehouse keeps saying "use the new keyword to create a gokart"
2 Answers
Harry James
14,780 PointsHey Abdur!
In this challenge, you want to create a new GoKart object. Here, you're creating a new example object with the variable name of GoKart.
With this information, see if you can rearrange that line to create a new GoKart object.
Here's the syntax for a variable in Java again if it helps:
ObjectType variableName = exampleValue;
Hope it helps but if you're still stuck, give me a shout :)
Sean McKeown
23,267 PointsI think you need to put your "Example GoKart = new Example();" line outside of the example class itself.
abdur rafay
1,933 PointsI tried it, it did not work
abdur rafay
1,933 Pointsabdur rafay
1,933 PointsOkay i tried what you said but it still did'nt work, either that or i didnt understand what you said properly.
Harry James
14,780 PointsHarry James
14,780 PointsSure thing! I'll try and rephrase what I've said.
Here is what you have written:
Example GoKart = new Example();
This created a new variable called GoKart of the type Example. We then set it to a new instance of the Example class.
What we want to do however, is create a new variable with a descriptive name (goKart in camel-case is a good bet!) of the type GoKart and set it to a new instance of the GoKart class.
See if this explanation helps you better. If you're still stuck, I can provide you with the answer so that you can see where you've gone wrong but I'd much rather you try and solve it for yourself You learn a lot better that way :)
abdur rafay
1,933 Pointsabdur rafay
1,933 PointsGokart goKart = new GoKart();
This is what i wrote after understanding your reply. But it is still not working ;-;
Harry James
14,780 PointsHarry James
14,780 PointsHey again Abdur!
You were close! Remember that the GoKart object is case-sensitive! Change this and the code will pass :)
abdur rafay
1,933 Pointsabdur rafay
1,933 PointsGoKart goKart = new GoKart();
Okay i checked everything, and i still don't get whats going wrong ;-;
Harry James
14,780 PointsHarry James
14,780 PointsOne last thing now!
The question asks you to pass in "a single parameter, color."
color is a String so just pass in any color you want,
"red
,"blue"
,"green"
etc... the choice is yours!This is passed in within the parentheses of the GoKart() constructor.
abdur rafay
1,933 Pointsabdur rafay
1,933 PointsOMG Thankyou so much I was making such a careless mistake.
Harry James
14,780 PointsHarry James
14,780 PointsHaha! No problem - glad you got through the challenge! :)
abdur rafay
1,933 Pointsabdur rafay
1,933 Pointsi hope you don't mind me asking you another question I seem to have run into another problem