Overriding is another useful feature of object-oriented programming technique. It provide the facility to redefine the inherit method of the super class by a subclass. The method overriding is used to invoking the parent class method by a child class. It is possible when a child class extends the parent class then all the attributes and the methods of parent class inherit by child class. The methods name and the parameters pass in the subclass are same as superclass methods. The restriction of the access modifier of the subclass method should not more than the superclass method e.g. if the superclass method is protected, the overriding method may be protected or public.
Here is an example of the method overriding. Create a class "Override" and create two subclasses "One" and "Two" and define a same method in both of them. When the main class call the method the method executes on behalf of their definition. In the given example we are trying to illustrate the same technique.
Here is the Code of the Example :
Here is the Output of the Example :
Rs. 20,000 US$ 300
Today: Rs. 10,000 US$150
Course Duration: 30 hrs
Posted on: June 17, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles