What are the differences and similarities between polymorphism and inheritance? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 7

What are the differences and similarities between polymorphism and inheritance?

What are the differences and similarities between polymorphism and inheritance?

14th Dec 2018, 5:06 PM
Zhenis Otarbay
Zhenis Otarbay - avatar
6 Answers
+ 12
BASICS Inheritance is creating a new class using the properties of already exists. Polymorphism is basically a common interface for multiple form. IMPLEMENTATION Inheritance is basically implemented on class. Polymorphism is basically implemented on function/methods. USE Inheritance used to support the concept of reusability in OOPS and reduce the length of code. Polymorphism allows objects to decide which forms of the function to be invoked when , at compile time (overloading)as well as runtime (overriding). Forms Inheritance may be a single ,multiple,multilevel,hierarchical &hybrid Inheritance. Polymorphism may be a compile time Polymorphism (over loading)or run time Polymorphism (over riding). EXAMPLE The class 'table' can be inherit the feature of the class 'furniture'as a 'table' is a furniture. The class 'study_ table 'can also have function 'set _color()'and a class .dinning_table' can also have function 'set_color ()' so ,which forms of the set_color () function to invoke can be
14th Dec 2018, 8:22 PM
AKS
AKS - avatar
+ 2
What are the differences and similarities between polymorphism and inheritance?
15th Dec 2018, 3:46 PM
Sunni Kumar
Sunni Kumar - avatar
+ 1
Inheritance is like, i have an interface named Animal. If Animal is having some methods like: public void speak(); All the classes or other interfaces who implements Animal, will have to implement these methods too. And about polymorphism is like i can have many constructors as i want, ej: public MyClass(){ ; } public MyClass(String name){ this.name = name; } And so on, as many as you need
14th Dec 2018, 7:37 PM
Jordi sarrato
Jordi sarrato - avatar
+ 1
1.Inheritance is a logical way of inheriting the parent properties into the child classes and the child class also has its own properties that are different from the parent. The child class can also have customized properties. Polymorphism is the way of giving same name to many functions. 2.As inheritance allows a derived class to use the elements and methods defined in the base class, the derived class does not need to define those elements or method it again so, we can say it increases code reusability and hence, reduces the length of the code. On the other hand, polymorphism makes it possible for an object to decide what form of the method it wants to invoke at both compile time and run time.
16th Dec 2018, 5:46 AM
SHWETA SHARMA
SHWETA SHARMA - avatar
0
Inheritence is mechanism that are that acqures all properties and behaviours of parent object while polymorphism its taking many forms example of polymophism is shape that can have diffent types of shapes like rectangle,triangle ,circle etc
17th Dec 2018, 8:56 PM
Emanuel James
Emanuel James - avatar
0
Inheritance is like a son taking the features of his father... while polymorphism is like casting a data type to have the features of another data type... for example : Float num =3;//3.0 Int mum =3.0//error From example above, let's take a look at this example of a dog class and an animal class: animal Rudy =new dog(); If we look at this , we can deduce that the features of animal as well as dog just like an int data type gives it's properties to the num allowing for calculations. Inheritance and polymorphism are similar in acquiring features and properties but different in concept and declarations
19th Dec 2018, 5:20 PM
Amaechi Chisom
Amaechi Chisom - avatar