Classes

 [Previous Chapter]  [Previous Page]  [Contents]  [Next Page]  [Next Chapter]

*In Java (and many other object-oriented programming languages) classes have two purposes:

*They declare a type (a reference type in Java) from which objects can be instantiated.
 
*They are the main units of encapsulation for information hiding.
 

*Classes consist of a name, constructors, a set of methods, and a set of instance variables (or attributes).
 
*Syntax in Java: Modifier class Identifier { Declarations }
 
*The modifier is usually public for top-level classes.
 
*Top-level classes should be stored in files carrying their name. The class BankAccount, for example, should be stored into a file named BankAccount.java. This allows the Java compiler to find the declaration of BankAccount if it is used elsewhere.
 

 [Previous Chapter]  [Previous Page]  [Contents]  [Next Page]  [Next Chapter]
Copyright © 2001, 2002 Andreas Borchert, converted to HTML on February 11, 2002