Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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! ;)