Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OverRiding Vs PolyMorphism

What is the difference between the two?

A super class having myMethod(int a) and an inheriting class having the same method, Is this overriding or polymorphism?

I am clear with the difference b/w overriding and overloading, but the polymorphism and overriding seems the same. Or are they?

like image 559
Kraken Avatar asked Sep 20 '11 17:09

Kraken


1 Answers

Overriding is when you call a method on an object and the method in the subclass with the same signature as the one in the superclass is called.

Polymorphism is where you are not sure of the objects type at runtime and the most specific method is called. Therefore the behaviour of the method called may differ, depending on the objects type at runtime.

Overriding is a type of polymorphism along with overloading and dynamic (late) binding. You can see more details here about the different types.

like image 144
adamjmarkham Avatar answered Sep 29 '22 13:09

adamjmarkham