PDA

View Full Version : What is Method Overriding?


rajesh
30-12-2009, 09:16 PM
When a class defines a method using the same name, return type, and argument list as that of a method in its superclass, the method in the subclass is said to override the method present in the Superclass. When the method is invoked for an object of the class, it is the new definition of the method that is called, and not the method definition from superclass.

Restrictions placed on method overriding

Overridden methods must have the same name, argument list, and return type.
The overriding method may not limit the access of the method it overrides. Methods may be overridden to be more public, not more private.
The overriding method may not throw any exceptions that may not be thrown by the overridden method.