Even that simple program shows how you can slip into trouble if you directly access the internal data of classes. The larger and more complex the program, the more important encapsulation becomes. And remember, many programs start out small and then grow to last indefinitely, so design them correctly, right from the beginning. To apply encapsulation to AlarmClock , you can just create methods to manipulate the snooze interval. Before I proceed, I should discuss methods in more detail.
Methods can return values that the caller uses.
To return a value, declare a nonvoid return type, and use a return statement. You do this by adding get and set methods for the snooze interval. Note that you are returning a value of type long here. Here's the line that returns the value. You use the set method.