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

how do I print out the getter?

I dont understnd how to work the getter

Example.java
public class Example {

    public static void main(String[] args) {
        System.out.println("We are going to create a GoKart");
        GoKart color = new GoKart ("red");
        System.out.printf("The GoKart color is %s\n",GoKart.getColor);
    }
}

1 Answer

Chase Marchione
Chase Marchione
155,055 Points

The issue here is that your current code is written as if it's attempting to call the getColor method on the GoKart class. What you want to do is call the getColor method on the actual object: you want to get the color of the new GoKart object you have created. You also need to use parentheses in your method call (this is a syntactical requirement.)

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

I also recommend choosing a name for the new GoKart object that has to do with it being a new GoKart. For example: goKart, or newKart.