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 trial

Java Java Objects (Retired) Meet Objects Creating New Objects

abdur rafay
abdur rafay
1,933 Points

Code is compiling but tree house is giving an error.

this is the code for the exercise

Example.java
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
Harry James
14,780 Points

Hey 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 :)

abdur rafay
abdur rafay
1,933 Points

Okay i tried what you said but it still did'nt work, either that or i didnt understand what you said properly.

Harry James
Harry James
14,780 Points

Sure 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
abdur rafay
1,933 Points

Gokart goKart = new GoKart();

This is what i wrote after understanding your reply. But it is still not working ;-;

Harry James
Harry James
14,780 Points

Hey again Abdur!

You were close! Remember that the GoKart object is case-sensitive! Change this and the code will pass :)

abdur rafay
abdur rafay
1,933 Points

GoKart goKart = new GoKart();

Okay i checked everything, and i still don't get whats going wrong ;-;

Harry James
Harry James
14,780 Points

One 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
abdur rafay
1,933 Points

OMG Thankyou so much I was making such a careless mistake.

Harry James
Harry James
14,780 Points

Haha! No problem - glad you got through the challenge! :)

abdur rafay
abdur rafay
1,933 Points

i hope you don't mind me asking you another question I seem to have run into another problem

Sean McKeown
Sean McKeown
23,267 Points

I think you need to put your "Example GoKart = new Example();" line outside of the example class itself.

abdur rafay
abdur rafay
1,933 Points

I tried it, it did not work