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 trialMUZ140667 Tawanda Shoko
4,152 Pointsrefactoring, adding a new member
How to add a new String member variable named mTitle and making it public?
public class PictureBook {
public String mTitle() {
}
}
2 Answers
Harry James
14,780 PointsHey there!
We can think of it just like a normal variable declaration (Note: This is not the answer to the challenge!):
private String example = "This is a string";
First comes the access modifier which in the example above is private
,
Next comes the variable type which in the example above is String
,
After that we have the variable name which in the example above is example
(Member variables should start with an m
!),
And finally, we have its value which must be the same as the type. In this case, it's This is a string
. We then close this out with a ;
.
Hopefully from the steps above you can decipher how to complete the challenge but if you get stuck on the way or if there's something you don't quite understand, give me a shout :)
MUZ140667 Tawanda Shoko
4,152 PointsI'm failing to make it right, where exactly I'm not coding well
Harry James
14,780 PointsSure thing!
What you've done is you've made a method rather than a variable.
Your answer for the challenge should look similar to what I've put in my answer above but read the question to see what you need to change (The variable name and access modifier).
If you're still stuck then I can provide the answer for you but I'd really like you to try for yourself first (By learning from your mistakes, you'll know for next time).
Let me know how it goes! :)