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 Classes

add a public field

how do i add a public to store the color of the class GoKart. to make it the set to the String of "red".
I am tired but i cant figure it out

GoKart.java
public class GoKart{}

 int color("red");

1 Answer

Richard Lu
Richard Lu
20,185 Points

From what I understand, you want to make the property color inside your GoKart class public. You can do this by simply adding public right next to the color property. Like this:

public int color;   // are you sure you want to make it an int?

It also looks like you're trying to assign it the color red, which you can do by using it equals operator. In the end it should come out to look like this:

public class GoKart {
    public String color = "red"; 
}

Great that works. And most importantly it makes sense. Thank you for the response,