PDA

View Full Version : Explain overridig with example 2011



saneha
04-29-2011, 07:34 AM
please explain overridig with examples

Vuhelper
04-29-2011, 07:34 AM
The Concept of Overriding is related with Inheritance.
You know that in inheritance, derived class has right to own all the data and behavior of its base class. It is seen practically that at least one situation might be occure among the below listed, while in inheritance under the concept of Overriding a function.

1- Derived class uses the overrided function as it is, from base class
2- Derived class extends somehow the behavior of Overrided function as per its needs
3- Derived class restrict somehow the behavior of Overrided function as per its needs.

Secondly, as you also know very well that Inheritance "is a" relationship i.e Triangle is a Shape, so in this sentence Triangle is the derived class of Shape.

Definitely, Triangle owns all the functionality of its base class Shape. Lets suppose there is a function” Draw" in its base class that can be accessed by an Object of Triangle and use it. But, in order to draw a triangle , some extension is required in the function Draw. So, this extension in the function of base class that is used by derived object as per needs is called extension in the existing functionality and is also known as sub typing.