Fallowing icon

Friday, October 5, 2012

Inheritance and Polymorphism



   

   In the Last lesson we discuss about Abstraction and Encapsulation. Now we discuss about Inheritance and Polymorphism.   


Inheritance


Concept of the inheritance



    
    One class object inheritance the data or behaviors with other classes objects. We can implement this using classes. 







      In this example, Vehicle class is a Supper class and others are sub classes. We extend Vehicle class for other classes. Then you can access one method in all this classes.





Polymorphism 




    When we are coding, we use different operations, But this single operation can have different behaviors in different object, We call it for Polymorphism.


Example-


      class Dongle{

          void dataTransferSpeed();
      } 



   The dongle data transfer speed is change time to time. Polymorphism is allowed different forms of the same service to be defined. We can implement the Polymorphism is using Overloading and Overriding. 

Overloading- 
            You can create methods in same name with using different parameter types. 

Overriding - 
            When you create one class in super class and sub class type (like above picture example), you can use same methods withing same parameter type in those classes.     
     

1 comment: