Constructors and encapsulation

Where should you reject an initial balance of -1?

Examples

Worked example

Input
A pass requires a nonnegative balance.
Expected output
In the constructor.

Hints and solution

Hint 1

Write down the starting state and walk through one example by hand.

Reveal worked answer

Every pass starts through its constructor, so the rule is enforced from the moment the object exists.

Back to the lesson