← Back to Week 5

Boolean Getters: is… / has…

Boolean getters answer a yes/no question. The Java convention is to name them like the question they answerisAdult(), not getAdult().

The "get" Style
public boolean getOccupied()
if (room.getOccupied()) { ... }
Reads as "if room get occupied" — awkward. Doesn't sound like English.
The "is" / "has" Style
public boolean isOccupied()
if (room.isOccupied()) { ... }
Reads as "if room is occupied" — sounds like the actual question. Easier to read out loud.
Pop Quiz — Rename the getter
Question 1 of 7 — Score: 0
The rule: Boolean getters describe a state. isAvailable(), isDirty(), isAdult(), hasReservation(), canCheckIn(). Most start with is for a state, has for ownership/possession, occasionally can for capability. The Java compiler doesn't care — it's a convention — but every Java codebase you'll join uses it.
← Derived Getters Default Access Modifier →