Witscale Test Center

11.3 Method overloading and overriding


11.3 Method overloading and overriding

Ideally, a method name should provide brief description of what the method does. You may often feel the necessity of reusing the same method name but have different implementation of method. There are two ways of doing this.

1.       You can reuse the same method name for the methods that take different arguments and possibly different return type. This technique is known as the method overloading.

2.       Alternatively, you can also reuse a method name of an inherited method (from super class) in a subclass to redefine that method. The redefined method must have exactly the same arguments and return type as the method defined in superclass. This technique is called as the method overriding.

Following sections discuss these two techniques in detail.