Previous | Next | Trail Map | Learning the Java Language | Objects and Classes in Java

The Class Body

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 -items Vector. It also defines one constructor--the default constructor-and four methods: push, pop, isEmpty, and finalize. Recall that finalize is a special method that provides for the clean up of Stack objects.


Previous | Next | Trail Map | Learning the Java Language | Objects and Classes in Java