> Education Commons > Java > Resources


  1. specification of public and private fields and the methods which operate on those fields
  2. consists of a public interface and a private implementation
    • the public interface consists of Javadoc, and the public class fields and public methods which the Javadoc describes
    • the private implementation consists of private instance fields and the code which implements both public and private methods
  3. a template for constructing objects
  4. all classes are subclasses of the Object class


  1. an instance of a class
  2. the action of creating an object is called instantiation
  3. a particular set of private fields, and the methods for operating on both public and private fields
  4. the state of an object is defined by the values of its instance fields and of the class fields (if any)
  5. in almost every case, the instance fields are private
  6. responsible for maintaining the integrity of its state
  7. every object of a class has knowing and doing responsibilities
    • knowing its state
    • changing its state
    • asking after the state of other objects
    • requesting changes in the state of other objects
  8. access to an object’s state is provided by special methods called accessors
    • accessors report an object’s state
    • accessors never change an object’s state
    • accessor identifiers either start with get or describe the value returned; ex: getBalance(); isTaxable()
  9. changes to an object’s state are effected by means of special methods called mutators
    • provided its preconditions (if any) are met, each mutator guarantees to maintain the integrity of the object on which it acts
    • mutator identifiers start with a verb describing the action performed by the method; ex: setColour(colour); deposit(amount)
  10. methods which create objects (instances of a class) are called constructors
  11. if a constructor is not provided, the default constructor—inherited from Object—is used

Constructor Methods

  1. initialize an object’s state
  2. are always public
  3. have the same name as their class
  4. may have different parameter lists
  5. may call their superclass constructor, but only as the first statement of the method body

Instance Fields

  1. contain an object’s state
  2. are declared at the top of a class
  3. are almost always private
  4. are initialized by constructor methods

Class Fields

  1. contain information shared by all instances of the class
  2. are declared above instance fields
  3. may be private or public
  4. if public, should be final > Education Commons > Java > Resources

[This page last updated 2020-12-23 at 12h13 Toronto local time.]