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

Error with code

Error with my code. I wish I could copy the error but I cant move this question box. Basically it doesnt like my last line. I am trying to show the location of the variable "getColor" but it does not like what I have.

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("%s",GoKart.getColor());

    }
}

1 Answer

Kevin Faust
Kevin Faust
15,353 Points

Hey Jonathan,

System.out.printf("%s",GoKart.getColor());

should be

System.out.printf("%s",color.getColor());

In the line above that, we created a GoKart object right? and we passed in a color String as its paramter ("Red"). What we want in our print statement is to grab the colour of the GoKart object we created. That's why you have to call the getColor() method on "color" (the name of the GoKart object you created)

What your doing now is calling the getColor() method on the class itself which you unfortunately cant do

Kevin