I know what is polymorphism. But came accross overriding polymorphism. what is that and when does it needed?
what is overriding polymorphism in OOP. Can please give example in php
214 views Asked by Ricky Sharma At
1
I know what is polymorphism. But came accross overriding polymorphism. what is that and when does it needed?
Glad to hear that you know what is "Polymorphism".
Let me explain you what is "
Overriding
" in Polymorphism.Say you have a class called..
Bird
I have put up a method called
fly()
, which is a common trait for a Bird. (Let's see.. O.o) . I have put up like every bird can fly. Well ok..Let us have another class called
Sparrow
which extends theBird
classSince it extends the
Bird
class, you can directly access the methodfly()
like this..Well now, Let us have another class called Duck that extends the Bird class (Assuming... Ducks don't fly), So we are ought to access the
fly()
it would print "I can fly" [We don't need that , so in this case we need to Override the method]Overriding the method !
Eventually if you do this.. you will get like this..
This is somewhat a basic explanation of "Method Overriding".