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 Privacy and Methods

My method is returning an error

I'm not sure why this method isn't working

public class GoKart {
public String mColor = "red":
public String getColorOfKart () {
return mColor;
}
}

10 Answers

It is not getColorOfKart it is only supposed to be getColor: public class GoKart { public String mColor = "red";

  public String getColor () {
    return mColor;
  }

}

surely it shouldn't matter what the method is called, as i'm just creating the method

This answer worked, but i really don't see what's the difference between my original code and yours, as you have just changed the method name !?

public class GoKart {

    public String mColor = "red";

    public String getColorOfKart () {
        return mColor;
    }

    public static void main(String[] args) {
        GoKart kart = new GoKart();
        System.out.println(kart.getColorOfKart());
    }
}

main is the JVM entry point into your program. When you run java GoKart the JVM looks for the main method signature.

Is that just one class from a bigger collection, or thats your entire program? If thats you're entire program then you're missing the main method

how would i do this sorry.

public class GoKart {
 public static void main (String [] args) {
public String mColor = "red":
public String getColorOfKart () {
return mColor;
}

}
}

that code doesn't work :/ Is there an error with this question ?

You had a : (colon) after "red" instead of required ; (semi-colon)

For the actual challenge you don't need the main, only the getColorOfKart method

public class GoKart {

    public String mColor = "red";

    public String getColorOfKart () {
        return mColor;
    }
}

that code doesn't work :/ Is there an error with this question ?

that code doesn't work :/ Is there an error with this question ?

that code doesn't work :/ Is there an error with this question ?

that code doesn't work :/ Is there an error with this question ?

that code doesn't work :/ Is there an error with this question ?

that code doesn't work :/ Is there an error with this question ?