Introduction
This article describes how method overridding works in Java. The Netbeans IDE is used for the develoment of examples.
What is Method Overridding
Method overridding is defined as having two methods with the same something in multiple classes and one method is overridden by another method. It is a part of polymorphism, polymorphism is a feature of Java. The word polymorphism means a formation of two; poly means many and morphism means forms, using polymorphism the object can take many forms. There are two types of Polymorphism as in the following:
- Static
Static polymorphism is defined as having two methods with the same name within the same class, for example Method Overloading.
- Dynamic
Dynamic polymorphism is defined as having two methods with the same name in different class, for example Method Overridding.
Feature Used for doing Overridding
For doing overridding in Java we use inheritance. Inheritance is a feature of Java in which a method of one class can be used in another class.
Rules for doing Method Overridding
- While overridding a method the argumentlist must be the same as for the overridden method.
- The method in the overridden class must not be protected or private.
- For overridding, a method must not declared final.
- For overridding, a method must not declared static.
- For overridding, a method must be inherited.
- In method overidding constructors cannot be overidden.
Example
In this example; we define method overidding using the Netbeans IDE. There are certain steps in the Netbeans IDE that we need to follow as explained below.
Step 1
Open the Netbeans IDE.

Step 2
Click on "File" from the Menu bar as in the following:

Step 3
Click on "New Project" as in the following:

Step 4
Select "Java" and "Java application" as in the following:

Step 5
Click on "Next" as in the following:

Step 6
Instead of project name specify "OverRiddingDemo" and instead of main class also specify "OverRiddingDemo" and click on "Finish".

Step 7
In this class write the following code (the class name is "OverRiddingDemo"):
class OverRiddingDemo
{




Vishal ChaturvediPosted Aug 5, 2013, 6:59 AM
thnkx sir...
Arvind PradhanPosted Aug 5, 2013, 6:54 AM
good write about over ridding in java