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

Android Build a Simple Android App (2014) Improving Our Code Creating a Class

Prasad Kothe
Prasad Kothe
359 Points

Now add a String member variable named mTitle. Make it public.

Now add a String member variable named mTitle. Make it public.

2 Answers

Hi Prasad,

You need to do pretty much what the question hints at; you've done the public class called PictureBook, now you want a public String called mTitle (inside the class):

public class PictureBook {
  public String mTitle;
}

I hope that helps.

Steve.

Thank you! For some reason I was struggling with this (perhaps because the class itself added a set of parenthesis before the semi colon). Fixed now. Much appreciated Steve.

HI there,

The video shows the addition of a method:

public String getFact() {
  // do stuff in here
}

That's an ability, not a property. While the code may look similar to this:

public String mTitle;

it is actually very different. The method has public access so code outside of the class can use it; it returns a String once it has run (not in my code; but you return a fact from the course code), it takes no input hence the brackets are empty, (), and the actions the method takes are enclosed with curly braces, {}. I've got nothing in there at the moment, but you copied all the fact generation stuff in between the braces, right?

The mTitle is a property; a member variable. It, too, has public access but is of type String, it is called mTitle. So whilst the two bits of code look similar, they do very different things. You'll see more of methods and variables as you progress through the Android and Java courses.

The video was wholly correct in adding the parentheses as it was showing you how to refactor a method. The challenge wanted you to create a property, so there's no brackets.

I hope that makes sense!

Steve.