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 trial1 Answer
Grigorij Schleifer
10,365 PointsHi jinhwa,
look at the comments in my code suggestions:
public class GoKart {
private String mColor;
public final static int MAX_BARS = 8;
// public means the variable is accessible from the class and outside that class
// final means the variable cannot be changed
// static means that you dont need an instance of the class to access
private int mBarsCount;
// field is the same as a variable
// classes have fields = field variables
public GoKart(String color) {
mColor = color;
mBarsCount = 0;
// initializing means assigning a value to a variable
// here we initialize the value 0 to mBarsCount
}
public void charge() {
mBarsCount = MAX_BARS;
// the charge method assigns the value of MAX_BARS to mBarsCount
// so now is mBarsCount = 8
}
public String getColor() {
return mColor;
}
}
Grigorij