Polymorphism is derived from two Greek words. Poly (meaning many) and morph (meaning forms). Polymorphism means many forms. In C you have two methods with the same name that have different function signatures and hence by passing the correct function signature you can invoke the correct method.
This is how polymorphism is achieved in languages like C where in a function sum(int, int) differs from sum(float, float). Therefore the method sum() has many forms depending on the parameters being passed to it.
The meaning with Object Oriented languages changes. With Object Oriented language polymorphism happens:
When the decision to invoke a function call is made by inspecting the object at runtime it is called Polymorphism.
This is how polymorphism is achieved in languages like C where in a function sum(int, int) differs from sum(float, float). Therefore the method sum() has many forms depending on the parameters being passed to it.
The meaning with Object Oriented languages changes. With Object Oriented language polymorphism happens:
When the decision to invoke a function call is made by inspecting the object at runtime it is called Polymorphism.
PHP 5 Polymorphism
Since PHP 5 introduces the concept of Type Hinting, polymorphism is possible with class methods. The basis of polymorphism is Inheritance and overridden methods.
Example:Since PHP 5 introduces the concept of Type Hinting, polymorphism is possible with class methods. The basis of polymorphism is Inheritance and overridden methods.
class BaseClass { public function myMethod() { echo "BaseClass method called"; }} class DerivedClass extends BaseClass { public function myMethod() { echo "DerivedClass method called"; }} function processClass(BaseClass $c) { $c->myMethod(); } $c = new DerivedClass();processClass($c);
Thanks for sharing this article with us. Keep sharing your ideas with us.
ReplyDeletecore java training in chennai
core java Training in Anna Nagar
best c c++ training in chennai
c c++ courses in chennai
C Language Training
javascript training in chennai
Appium Training in Chennai
JMeter Training in Chennai
Just an awesome and information. keep blogging more.
ReplyDeleteAngularJS training in chennai | AngularJS training in anna nagar | AngularJS training in omr | AngularJS training in porur | AngularJS training in tambaram | AngularJS training in velachery
Great Post, Thanks for sharing the information.
ReplyDeletemachine learning training in bangalore
Thank you for sharing such a useful post.
ReplyDeleteMicrosoft Power Platform Online Course from Malaysia
Fusion PPM Online Course from Malaysia
OAM Training Institute In Bangalore
Talend Certification Training In Singapore
Best SSAS Training from Hyderabad
Master Data Management Training Certification Training In India