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

Creating New Objects

Hi All,

Could you please paste how this exercise should look like ??

I cannot pass this track and dont know where I am wrong .

Thank you in advance , GamingWithHan

Example.java
public class Example {

    public static void main(String[] args) {
        System.out.println("We are going to create a GoKart");
    }
}

4 Answers

foxtails
foxtails
3,655 Points

public class Example {

public static void main(String[] args) {
    System.out.println("We are going to create a GoKart");
    GoKart color = new GoKart("green");  //Here goes class name (you chose which color you want)
    System.out.printf("This GoKart is %s.\n",
                     color.getColor());  //Here goes parameter
}

}

thanks foxtails

Before we can use a class (like GoKart), we have to create a GoKart object by instantiating it.

In Java, we do so like this:

GoKart variablename = new GoKart();

Because the GoKart requires a colour parameter, we would simply put the colour in the parenthesis.

GoKart variablename = new GoKart("blue");

I hope this helps!

Thanks so much!!

foxtails
foxtails
3,655 Points

Yes, that one got me thinking as well. There were too many Pez dispensers in example to see difference, where the class is written and where the parameter goes.

yea

how did you do it then foxtails

foxtails
foxtails
3,655 Points

You are welcome! ;)