HELP! * GREY=local LOCAL HTML version of Foils prepared July 10 1996

Foil 76 Comments on Overloading and Overriding in Classes

From Basic Lectures on Java Language Applets Graphics Networking Trip to China and Icase Tutorial -- July 12-28 and June 10-13 96. by Geoffrey C. Fox * See also color IMAGE

Overriding Methods
  • To override a method, a subclass of the class that originally declared the method must declare a method with the same name, return type (or a subclass of that return type), and same parameter list.
  • When the method is invoked on an instance of the subclass, the new method is called rather than the original method.
  • The overridden method can be invoked using the super variable.
  • Super can be used to refer to instance variables in the superclass as well.
Overload Resolution is based on what is called the Signature of a Method (see Arnold-Gosling book) which reflects:
  • Lowest conversion cost of parameter list, based on type and number.
  • Return type and declaration order not important.
  • Java will declare an error if method is invoked where there is not one with a unique signature which matches call after removing less specific methods (use of objects in hierarchy can cause lots of confusing matches!)



Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Tue Feb 18 1997