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

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

Does anyone know what is wrong with my code?

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

    }
}

It says in the output.html: System.out.printf("The result from the method is %s", goKart.getGoKart()); With an arrow under the "." after goKart

1 Answer

Rob Bridges
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Rob Bridges
Full Stack JavaScript Techdegree Graduate 35,467 Points

Hey Peter,

You are giving yourself more work than than you have to for this challenge, we don't need to declare a variable for Color, the testing code already has it available.

Really you have the code you need to pass the challenge, however cut off the top part and leave yourself with.

public class Example {

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

That will pass the challenge.

Thanks shoot back if you're still having trouble.

Thank you very much, that shot me straight through!!