![]() ![]() We are calling the walk() method by the reference variable of Parent class. In below example we create two class Person an Employee, Employee class extends Person class feature and override walk() method. In dynamic polymorphism method of the program binds with an object at runtime the advantage of dynamic polymorphism is allocating the memory space for the method (either for overloaded method or for override method) at run time. ![]() In C++ environment the above problem can be solve by using dynamic polymorphism by implementing with virtual and pure virtual function so most of the C++ developer in real worlds follows only dynamic polymorphism. The process of binding the overloaded method within object at compile time is known as Static polymorphism due to static polymorphism utilization of resources (main memory space) is poor because for each and every overloaded method a memory space is created at compile time when it binds with an object. Runtime polymorphism (dynamic binding or method overriding).Compile time polymorphism (static binding or method overloading).In java language, polymorphism is essentially considered into two versions. Object o = new Object() //o can hold the reference of any subtype An example of polymorphism is referring the instance of subclass, with reference variable of super-class. Its not only Java but other object oriented language like C++ also supports polymorphism and it comes as fundamental along with other OOPS concepts like Encapsulation, Abstraction and Inheritance. If we don't use common interface and rely on concrete implementation, we always need to change and duplicate most of our code to support new implementation. When we program for interface our code is capable of handling any new requirement or enhancement arise in near future due to new implementation of our common interface. Polymorphism is an Oops concept which advice use of common interface instead of concrete implementation while writing code. Polymorphism is one of the major building blocks of object oriented programming along with inheritance, abstraction and encapsulation. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |