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 trialNeelesh Tewani
1,239 Pointsmethod returned 1 but expected 139 "a" this is the error
public int getLength(){ int LENGTH = mText.length(); return LENGTH; }
public class Tweet {
private String mText;
public static final int CONSTANT = 140;
public Tweet(String text) {
mText = text;
}
public int getLength(){
int LENGTH = mText.length();
return LENGTH;
}
public String getText() {
return mText;
}
}
3 Answers
Ken Alger
Treehouse TeacherNeelesh;
We need to be subtracting the length of mText
from our constant to get how many characters are still available, right? So if our "Tweet" has five characters in it, our method should return the value of 140 - 5.
Using the variable name you used we should be able, therefore, to make our return statement:
return CONSTANT - mText.length();
Post back if you have further questions.
Happy coding,
Ken
Neelesh Tewani
1,239 PointsCan You Tell Me the difference between static and final
Chiranjeev Dahiya
2,139 PointsIn Java we use Static to access any method or data variable without making instance of that class.for e.g
public class abc{
static int a = 10 ; }
we can use this variable class name like :- abc.a = 20;
where as we can use final keyword in three ways:-
1) Variable = Make constant through out the program. 2) method = does not override it in inheritance. 3) class = class cannot be inherited.