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

Having trouble using the getColor method for a challenge.

I think I'm meant to be using different objects for this, and I'm not exactly sure where I'm going wrong.

P.S: I'm worried I rely to much on looking back at the workspace to help me through the challenges. Is that a problem, or will it stop be from really learning this language.

Thanks!

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("color");
      System.out.printf("The kart color is %s\n", GoKart.getColor());
    }
  public class GoKart {
    private String mColor;
    public GoKart (String color) {
      mColor = color;
    }



    }
}
Michael Narvaez
Michael Narvaez
4,182 Points

What errors are you getting ?

1 Answer

Kane Stoboi
Kane Stoboi
21,919 Points

It does not seem like you need to create the GoKart class in the code challenge.

Try removing these lines.

public class GoKart {
    private String mColor;
    public GoKart (String color) {
      mColor = color;
    }



    }

Also when you are trying to get the color from the getColor method you are not referencing the "kart" object that you created. Perhaps try checking out the video again.

I don't think looking back through the videos is negatively impacting on your learning just so long as you are understanding the concepts. I try not to reference the videos too much when doing the challenges but I make sure I understand the concepts before doing them and if I'm having trouble I try to look at the java documentation.