Android Build an Interactive Story App The Model-View-Presenter Pattern Adding Custom Constructors

Yusuf Mohamed
Yusuf Mohamed
2,607 Points

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
171,091 Points

Different how? What are you comparing this to?

Adam Shockley
Adam Shockley
3,896 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
MOD
Seth Kroger
Treehouse Moderator 56,253 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.