Comparison: Inheritance & Polymorphism
Comparison Inheritance & Polymorphism
Inheritance is the mechanism by which an object inherits all the properties and behaviors of its parent object. This is an important part of OOP (Object Oriented Programming System).
Terminology used in inheritance
Class: A class is a group of objects that share common properties. This is the template or blueprint from which the object was created.
Subclass / Subclass: A subclass is a class that inherits from another class. It is also called a derived class or child class.
Parent Class: It is the class from where the features are inherited by subclass. also called a base class/parent class.
Reusability: As the name seggests, reusability is a mechanism which facilitates you to reuse the fields and methods of the existing class when you create a new class.You can use the same fields and methods as defined in the previous class
syntax. class subclass name extends superclass name
Types of inheritance in java
Based on the class, Java has three types of inheritance: simple, hierarchical and multi-level. In Java programming, multiple hybrid inheritances are only supported through the interface.
Polymorphism
Java polymorphism is a concept that allows you to perform a single action in different ways Polymorphism comes from the two Greek words poly and morphs.. The word "poly"-(lot), and "morph"-(form). Therefore, polymorphism means many forms.
Example of polymorphism
Types of polymorphism:
Java has two types of polymorphism: compile-time polymorphism and run-time polymorphism. Method overloading and method overriding allow you to perform polymorphism in Java. If you are overloading static methods in Java, this is an example of compile-time polymorphism. Here we will discuss Java runtime polymorphism
Runtime polymorphism:
Runtime polymorphism, or dynamic method dispatching, is the process by which overridden method calls are resolved at run time rather than at compile time.
Run-time polymorphism determines the behavior of a method at run time.
Therefore, at run time, the JVM (Java Virtual Machine) binds the method call to the method definition / body and at run time calls the relevant method when the method is called. This happens because the object is created at run time and the method is called through the object of the class. The Java compiler has no awareness of the method to be called on an instance during compilation. Therefore, JVM invokes the relevant method during runtime. Runtime polymorphism can be implemented / implemented in Java using method overrides. Method overriding is a mechanism that overrides a base class method in a derived class to provide a more specific implementation. The method signatures of the base class and the derived class are the same, but only the implementation is different.
Compile time polymorphism:
The polymorphism that appears during compilation is called static polymorphism in Java. In static polymorphism, the behavior of a method is determined at compile time.Therefore, the Java compiler binds method calls to the method definition / body during compilation. Therefore, this type of polymorphism in Java is also known as compile-time polymorphism.
Example:
difference between Inheritance & Polymorphism
Conclusion
It is no exaggeration to say that both polymorphism and inheritance are important concepts in implementing a program. Both are the basis of the idea of object-oriented programming. There are many differences between polymorphism and inheritance because they have two very different purposes.
One thing to keep in mind when writing code is that you want to refactor the code you've already written (basically defining a class and reusing it in your code to serve similar or different purposes. increase). You must use inheritance. Consider using polymorphism if you want to reduce the overall confusion of your code and use the same function names for similar tasks.
Thank you for reading .....
Published by:
Pratiksha Bandole
Pritam Bhatkar
Abhishek Degil
Yash Ganbote
Vedika Gosavi
Good content written but
ReplyDeleteMore deep content can be added.
Great stuff guys. Real important and instructive stuff. Noice job
ReplyDeleteImportant information.....
ReplyDeleteVery informative 📜.. nice work guys 👍🏻
ReplyDeleteVery informative blog. Each contents are really good
ReplyDeleteAmazing write-up Team! The way you cover this topic in a single blog with excellent content is really appreciated. Keep it up.
ReplyDeleteVery Informative blog
ReplyDeleteGood Works Guys .... Keep it up
ReplyDeleteGood 👍
ReplyDeleteGood one 👍🏼
ReplyDeleteInformative Blog
ReplyDeleteKeep it up Guy's
ReplyDeleteNice 👍
ReplyDelete👍🏼👍🏼
ReplyDeleteThanks for sharing such a great information.. It really helpful to me..I always search to read the quality content and finally i found this in you post. keep it up! Guys
ReplyDeleteNice keep it up
ReplyDeleteImpressive Blog keep it up Guy's
ReplyDeleteInformative
ReplyDeleteGood work
ReplyDeleteEnjoyed reading the blog above , really explains everything in detail, the blog is very interesting and effective. Thank you and good luck in the upcoming blog.
ReplyDelete👍👍
ReplyDeleteNice👍
ReplyDeleteKeep it up
ReplyDeleteGood vlog
ReplyDeleteNice content
ReplyDeleteSuperb
ReplyDeleteAmazing work
ReplyDeleteGood one
ReplyDeleteNice🤌🏻
ReplyDeleteVery nice information 👍👍
ReplyDeleteNice👍🏻
ReplyDelete👍
ReplyDeleteKeep it up bro
ReplyDeleteExcellent
ReplyDeleteGood work
ReplyDeleteVery bice👍
ReplyDeleteVery nice and informative
ReplyDeleteThe way you cover this topic in a single blog with excellent content is really appreciated. Want more such blogs !!!
ReplyDeleteExcellent work guys!!
Very nice
ReplyDeleteYou guys done the great job Overall each information get covered in a blog and it’s quite informative for me!😊Keep it up guys!!
ReplyDeleteNice 👍
ReplyDeleteNice 👍
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteVery nice👍
ReplyDeleteAmazing helpful, enlightening and informative this blog is. I would suggest all students interested in this field to read this blog. Had fun reading this one. Great work guys
ReplyDeleteGreat content guys👍🏽. Found this when i was surfing over the net for 3D materials and found this blog very informative and useful. Loved how the past , present and he future of hybrid algorithm method was mentioned in detail. I enjoyed reading this blog and this is beneficial for students etc. You guys have my gratitude for this great stuff.
ReplyDelete