Home : Course Map : Chapter 4 : Java : Supplements :
Overriding vs Overloading
JavaTech
Course Map
Chapter 4

Introduction
Inheritance
  Demo 1
Overriding
  Demo 2a
  Demo 2b
this,super
MoreConstructors
  Demo 3
Abstraction
Interface 
  Demo 4
Casting References
MoreAboutArrays
Object class
Class Summary
Exercises

    Supplements
Override/Overload
Annotation-J2SE5.0
Java Security
Class Loading
Class Verifier
SecurityManager
     About JavaTech
     Codes List
     Exercises
     Feedback
     References
     Resources
     Tips
     Topic Index
     Course Guide
     What's New

Don't get overiding and overloading confused.

You can think of overloading as expanding the versions of a method along the horizontal axis. For example, here we show class A with several overloaded versions of the do() method:

public class A {
  ...
  void do ()
  {..}
  void do (int i)
  {..}
  void do (float x)
  {..}
  void do (float x, float y)
  {..}
}
A: do () do (int i) do (float x) do (float x, float y)

 

We display the various versions of do() in columns on the horizontal axis.

Below we show two subclasses of class A. Inheritance allows subclasses to override some or all of these versions of do() and also overload new ones. We show the methods of the base class and subclasses vertically below the base class.

Here class B extends class A and overrides three of the do() methods. Class C extends class B and overrides the do(int i) method in class B:

 public class B extends A
 {
  ...
  void do (int i)
  {..}
  void do (float x, float y)
  {..}
  void do (float x, int k)
  {..}
 }

 public class C extends B
 {
  ...
  void do (int i)
  {..}
 }
A: do () do (int i) do (float x) do (float x,float y)  
B: " do (int i) " do (float x,float y) do (float x,int k)
C: " do (int i) " " "

 

Here the quotation mark " indicates that the code of the inherited method above it is used. Where a class method signature is written, the method overrides the inherited version.

The base class A overloads the do() function with four different variations.

Class B is a subclass of A and inherits its four methods but overrides two of them and overloads with a new one of its own.

Class C is a subclass of B and inherits two do() methods from class A and two from class B. It overrides one method from class B.

Latest update: Oct. 24, 2004

            Tech
MoreComplexClass
ImprovedHistogram
JavaRandomNums
Vectors & Matrices
Exercises

           Physics
Runge-Kutta 2nd
  Demo 1
Runge-Kutta 4th
  Demo 2
BoundaryVal.Prob
Shooting Method
  Demo 3
Exercises

  Part I Part II Part III
Java Core 1  2  3  4  5  6  7  8  9  10  11  12 13 14 15 16 17
18 19 20
21
22 23 24
Supplements

1  2  3  4  5  6  7  8  9  10  11  12

Tech 1  2  3  4  5  6  7  8  9  10  11  12
Physics 1  2  3  4  5  6  7  8  9  10  11  12

Java is a trademark of Sun Microsystems, Inc.