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 trialBorislav Milev
1,218 PointsEnsure you've created a new public int field following the constant naming convention of MAX_CHARS
Can someone tell me what I am doing wrong and a quick and simple explanation on what a field is. Thank you!
public class Tweet {
private String text;
public Tweet(String text) {
this.text = text;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public final static int MAX_CHARTS = 140;
}
3 Answers
james south
Front End Web Development Techdegree Graduate 33,271 Pointsyou spelled chars wrong. additionally, and these won't throw an error, but typically this would be put at the top before any methods, and static goes before final.
james south
Front End Web Development Techdegree Graduate 33,271 Pointsa field is just a variable in a class, so max_chars is a field and so is text. text is private so it can only be accessed by code in this class. max_chars is public so it can be accessed from any class in the application. text is not static, so it belongs to the instances of the class. each instance has its own value for text, which makes sense, each instance of a tweet is different. to access the non-static field text you need an object (instance) of the class. max_chars is static, so it belongs to the class. this makes sense here because all tweets have a max length of 140 chars. that value stays constant no matter how many tweets we make or if we make any at all. since this value is not going to change and exists irrespective of instances of the class, we make it public static final.
Borislav Milev
1,218 PointsThank you guys! I learned a bit more :)
William Schultz
2,926 PointsWilliam Schultz
2,926 PointsI don't know Java, but you have a Syntax error. The challenge is asking for MAX_CHARS not MAX_CHARTS. I tested it and it works fine spelled right. I also would declare this right below the declaration of text at the top instead of below your methods.