![]() ![]() Fall Semester 2016 | |
Previously on C212: Implementing Classes
Java programs are made out of classes. There's nothing there except classes. Classes are containers. They hold
static members and instance members. (Members are variables and methods.) Instance members collectively form
the blueprint used to instantiate objects. A special kind of method look-alike is the constructor, which acts
as an initialization procedure at instantiation. We practice these concepts by designing a
Counter (complete with tester). We take our design further
by modeling a BankAccount (just a sketch
so we don't have a tester just yet. Here's a finished version
of our model, also shown here (along with
a tester program). We continue to hone
our newly acquired skills by designing a
CashRegister
(complete with tester). Next
we revisit the concept of local variables
in this context (instance methods) and write
a simple tester for that too.
We say that class variables (also known as static ) should be referenced
via the class they belong to, and instance variables, likewise, via the instance they
are part of. It follows that a special reference
(this ) is available and can be used for self reference in constructors and instance
methods. We stop where the optional sections of the chapters start.
| |
Updated by Adrian German for C212/A592 |