OverRiding Vs PolyMorphism

后端 未结 4 2256
醉梦人生
醉梦人生 2020-12-29 10:29

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 poly

4条回答
  •  北海茫月
    2020-12-29 11:10

    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.

提交回复
热议问题