Basic HTML version of Foils prepared 18 May 97

Foil 52 Comments on Overloading and Overriding in Classes

From Java Tutorial - Spring 1997 Part II: Java Language and Object-Oriented Concepts Peking Tutorial, Web Certificate -- Spring-Summer 1997. 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 Thu Jan 8 1998