Override vs Overload

2011-03-31


Here is a nice article about Overload vs Overriding:

Q: Method Overloading?

Ans:

Method overloading means having two or more methods with the same name but different signatures in the same scope. These two methods may exist in the same class or anoter one in base class and another in derived class. When to use Method Overloading?

Generally, you should consider overloading a method when you have required same reason that take different signatures, but conceptually do the same thing.

Q: Method Overriding?

Ans:

Method overriding means having a different implementation of the same method in the inherited class. These two methods would have the same signature, but different implementation. One of these would exist in the base class and another in the derived class. These cannot exist in the same class.

Overriding methods

Overriding method definitions

In a derived class, if you include a method definition that has the same name and exactly the same number and types of parameters as a method already defined in the base class, this new definition replaces the old definition of the method.

For example: When the overriden method (getArea) is invoked for an object of the Cylinder class, the new definition of the method is called and not the old definition from the superclass(Circle).