Basic HTML version of Foils prepared 9 Sept 1997

Foil 33 Comments on Overloading and Overriding in Classes

From Java to be used in (Scientific) Computing Part II: Java Language and Object-Oriented Concepts Basic Simulation Track for Computational Science CPS615 -- Fall Semester 97. by Nancy J. McCracken,Geoffrey C. Fox


1 Overriding Methods (where child class provides method with same signature as method in parent)
  • 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.
2 Overloading (where a class can provide a set of methods all with the same name, but with different signatures): The signature is defined (as in Arnold-Gosling book) by
  • Lowest conversion cost of parameter list, based on type and number of parameters. 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!)

in Table To:


© 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 Sun Feb 22 1998