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

Brandon Wash
Brandon Wash
Courses Plus Student 1,186 Points

Print out using System.out.printf the color of the new object, using the getColor method

Can someone tell me where i messed up at? This coding is really confusing. Any suggestions on how to make it easier to understand?

public class Example {

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


3 Answers

Brandon Wash
Brandon Wash
Courses Plus Student 1,186 Points

I think you explained it well... Just not sure to to write out the code properly.

Tobias Edwards
Tobias Edwards
14,458 Points

Firstly, Java is a difficult language so don't worry if you mess up! I would suggest looking over the previous video to try and make more sense of it. Here's my answer anyway:

The first challenge asks you to create a new instance of the GoKart class, you have called your instance goKart. The GoKart class takes one parameter - the color of the go-kart. While you have passed in a string argument - ("") - I would suggest your pass in a color like green, blue or red in between the speech marks. Also, for style points, try not to put a space between the instance and it's parameters. For example:

// don't do this
GoKart goKart = new GoKart ("Blue");

// do this
GoKart goKart = new GoKart("Blue");
// this helps clarify things

For the second challenge, you have to print the color of the go-kart by accessing the getColor method that is inside the goKart instance your created. So instead of trying to access the getColor method through color (The compiler's thinking: "WHAT's 'color'???!?!!?!"), you need to access the getColor method from the goKart instance your created.

I hope that cleans things up a bit, although I don't think I'm too good at explaining things.

EDIT: For clarification, I would type a color between your (""), otherwise when your accessing the getColor() method later on, this will retrieve nothing. Secondly, you need to access the getColor() method from the goKart instance, not color. So just change color to the name of the instance you created.

In the line: System.out.prinf("New Gokart is %s\n",color.getColor() ); You forgot the t at the end of printf.