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

Kenneth Kimbrell
PLUS
Kenneth Kimbrell
Courses Plus Student 6,816 Points

Can't figure out where I went wrong here

I need help seeing where I went wrong with this code

Example.java
public class Example {

    public static void main(String[] args) {

   new Color("RED");
   System.out.printf("The new GoKart color is %s\n ", getColor());

        System.out.println("We are going to create a GoKart");
    }
}

1 Answer

Aaron Kaye
Aaron Kaye
10,948 Points

Ok so a couple of things went wrong, you need to create an instance of the GoKart class:

Class (Capitalized by convention) Variable to hold the instance of the class (camelCase) and you need to set it equal to the newly created instance. In this case, our kart takes a single parameter, color. We can create an instance of our GoKart class as follows:

GoKart goKart = new GoKart("red");

Now that we have the instance saved in the variable (goKart), we can perform methods on it using the following convention:

goKart.getMethod();

In this case, you need to get the color using the getColor() method. Hope this helps! Good luck and have fun studying Java!