Objects and Classes in Java |
The class body contains all of the code that provides for the life cycle of the objects created from it: constructors for initializing new objects, declarations for the variables that provide the state of the class and its objects, methods to implement the behavior of the class and its objects, and when necessary, a finalize method to provide for cleaning up an object after it has done its job.Variables and methods collectively are called members.
Note: Constructors are not methods. Nor are they members.
The
Stack
class defines one member variable in its body to contain its elements-the -itemsVector
. It also defines one constructor--the default constructor-and four methods:push
,pop
,isEmpty
, andfinalize
. Recall thatfinalize
is a special method that provides for the clean up ofStack
objects.
Objects and Classes in Java |