Hello Readers
If we break the word Polymorphism poly means many (Poly = many) and morph means change (
Morph = change or form).
Its basically the concept of object oriented programming (OOPS) in which classes have differernt functionality and use a common interface.
or its a concept in OOPs which allows the programmers to know what they must know.
Its a feature or characteristic in OOPs that helps the developers to make our code to be more flexible, easier to maintain, and more dynamic in nature.
With the use of polymorphism you can provide any instance of a given base class and run the time interpreter to determine the concrete implemantation.
Lets look the example of polymorphism:
class BaseClass {
public function myMethod() {
echo "BaseClass ";
}
}
class DerivedClass extends BaseClass {
public function myMethod() {
echo "DerivedClass";
}
}
function processClass(BaseClass $c) {
$c->myMethod();
}
$c = new DerivedClass();
processClass($c);
OUTPUT:
DerivedClass
In the above example we can use two class one is BaseClass and the other is DerivedClass,so in this object $c of class DerivedClass is executed.
0 Comment(s)