Calling a Method

Purpose:

To tell an instance to perform a capability.

Mechanics:

<instance name>.<method name>();

Example:

shape.animate();

Usage:

  • <instance name> is the name of an instance that has already been constructed.
  • <method name> is a method defined in the class of that instance. When this statement is encountered in a method, Java sends the <method name> message to <instance name>.
  • The next statement is not executed until <instance name> has completed the behavior defined in <method name>.

Restrictions:

If this statement appears in a method of a class which is in a different package than the class of which <instance name> is an instance defined, then <method name> must be declared public. If the method is part of a class in the same package, then the method must not be declared private, unless the method is sending a message to another instance of the same class.
Back to the Table of Contents
email suggestions to: cs015tas@cs.brown.edu