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 an Interactive Story App The Model-View-Presenter Pattern Adding Custom Constructors

Could someone explain the logic in this boolean?

Ok so in this video he generated a getter and setter but for the getter and setter that was of a boolean value it was a bit different. Here's the code

public boolean isFinalPage() {
        return isFinalPage;
    }

    public void setFinalPage(boolean finalPage) {
        isFinalPage = finalPage;
    }
Steven Parker
Steven Parker
231,198 Points

Different how? What are you comparing this to?

Adam Shockley
Adam Shockley
4,548 Points

Booleans are false by default in java. So if setFinalPage is never ran then isFinalPage will always return false.

setFinalPage takes a parameter that determines whether final page will be true or false.

You could put anything that returns a boolean as the parameter for setFinalPage or even just true or false.

setFinalPage(true);

if (isFinalPage()) {
   System.out.println("This is the final page");
}

The above code would display This is the final page in the console.

1 Answer

Seth Kroger
Seth Kroger
56,413 Points

If you are talking about the naming convention, "is" replaces "get" with boolean values. This makes its common use in if statements clearer and more natural to read.