Search⌘ K

Boolean-Valued Methods

Explore the concept of Boolean-valued methods in Java, focusing on how methods such as isLeapYear return true or false to reflect object states. Understand how to define and use these methods in class definitions to improve readability and functionality of your programs.

The chapter Using Classes and Objects introduced methods that compare two objects and return a value based on the result of the comparison. In particular, we described the method equals for the class String. This method tests whether two strings are the same by returning either true or false. Further, we gave an example of using an if statement to react to the result of String’s equals method. Classes often include methods like equals that return a Boolean value.

A Class of calendar dates

Imagine a class that represents a date consisting of a month, day, and year, where ...