OverRiding Vs PolyMorphism

后端 未结 4 2185
醉梦人生
醉梦人生 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.

    0 讨论(0)
  • 2020-12-29 11:14

    Overriding of methods is one type of Polymorphism only. It's mentioned very clearly in the below article. Link is provided below.

    Overriding vs Polymorphism

    0 讨论(0)
  • 2020-12-29 11:26

    I am doing my software architecture exam tomorrow, and this is what i have understood from my reading.

    Polymorphism is a concept of object oriented programming that allows a field, in this case, an object, to be changed from one form to another. Poly = multiple, morph = change.

    Overriding a method, is essentially a dynamic binding of a method which allows a method to be changed during run-time. It is a form of polymorphism since a method's functionality gets changed over the course of time.

    I took some of my facts from here - https://beginnersbook.com/2013/03/polymorphism-in-java/

    0 讨论(0)
  • 2020-12-29 11:28

    yes...by using overriding we achieve the property of polymorphism ...when u have multiple class deriving from a single parent class ...there by using overriding ...we define the derived class method's functionality and as they are derived from same parent we show the property of polymorphism..

    0 讨论(0)
提交回复
热议问题