Chapter 8: Designing Classes
Preconditions and Postconditions
- Precondition: amount >= 0
- assert amount >= 0; // assertions must be enabled
- Postcondition: getBalance() >= 0
- assert getBalance() >= 0; // assertions must be enabled
- Some javadoc extensions support @precondition and @postcondition tags
static
- methods, also called class methods, e.g. Math.random();
- variables, also called class variables (or fields),
e.g. private static int lastAccount = 1000;
Scope Rules
- The scope of a variable is the region of a program where the variable
can be accessed.
- Instance Variables, Instance Methods -
can be qualified with this.
- Class Variables, Class Constants, Class Methods -
can be qualified with name of class
- Method Parameters
- Local Variables
Lecture Code
We continued to modify and comment the solution to Program 1
to illustrate some of the above concepts.