definition - What is polymorphism, explained simply? -


i know duplicate question , little "soft" have not liked of other explanations out there , hear simple response not generalize confusing.

for example what polymorphism, for, , how used?

is polymorphism "being able perform functions (or methods?) of interface, such adding, subtracting, etc, on objects of different data types such integers, floats, etc"?

is operator overloading? or templating?

polymorphism fancy word means can use more general term refer specific type of object.

it goes hand in hand interfaces

interface: same word, several flavours

instead of saying "i got new vauxhall corsa", "i got new car". statement true if you'd got ford fiesta, car. flexibility (polymorphism) of english word 'car' means don't have specify kind of car is. audience know have modern contraption on front drive designed beep, steer, , drive down road, though exact mechanisms of vauxhall , ford engines may different each other.

polymorphism takes interface , lets refer ford fiesta car:

car car = new ford(); 

from this blog:

polymorphism means using superclass variable refer subclass object. example, consider simple inheritance hierarchy , code:

abstract class animal {     abstract void talk(); } class dog extends animal {     void talk() {         system.out.println("woof!");     } } class cat extends animal {     void talk() {         system.out.println("meow.");     } } 

polymorphism allows hold reference dog object in variable of type animal, in:

animal animal = new dog(); 

ps given other answers, may want know the difference between abstract class , interface.


Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -