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

I am having trouble with challenge 2 of 2 on the java objects

public class Example {

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

} this is my code, can some one hellp?

Example.java
public class Example {

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


}

2 Answers

Edith England
Edith England
4,270 Points

You need to specify that the getColor method is being called on the goKart object.

eg

GoKart goKart=new GoKart("blue"); System.out.printf(goKart.getColor());

Ryan Ruscett
Ryan Ruscett
23,309 Points

It's actually kart.getColor since the reference to the object is kart but yup, you are right!

System.out.printf(goKart.getColor()); Worked for me. Thanks

Ryan Ruscett
Ryan Ruscett
23,309 Points

That's because you copied Edith's string. Edith's string used GoKart and YOUR string used kart. So to fix your code it's kart to copy Edith's it's well, copy paste.