Polymorphism in Java. In English
Polymorphism
In Java, polymorphism is the idea that allows us to execute a single action in multiple ways. The words poly and morphs are both Greek words. The definition of "morphs" is shapes, while "poly" means many. Hence, polymorphism refers to variety. One of the key components of object-oriented programming is polymorphism.
After a subclass overrides a superclass method, polymorphism is the process of uploading and implementing subclass methods through the superclass reference.
There are two types of polymorphism in Java.
1.Compile-time polymorphism
2.Runtime polymorphism
Compile-time polymorphism......................
Another name for it is static polymorphism. Operator overloading or function overloading are the methods used to achieve this kind of polymorphism.
There are three subtypes of compile-time polymorphism.
1. Function Overloading - Multiple functions with different argument lists can share the same name thanks to a feature in C++. Based on the quantity and kind of arguments supplied to the function, the compiler will select which function to call.
2.Operator Overloading - When applied to user-defined data types, operators like +, -, *, and so forth can take on new meanings thanks to a feature in C++.Java doesn’t support the Operator Overloading.
3.Template - The ability to create generic classes and functions is a strong feature of C++. A template is a set of instructions used to create a class or family of functions.
Method Overloading
- Permits objects of various classes to be handled as objects of a common class, increasing the reusability of code.
- Reduces the quantity of code that needs to be written and maintained, which improves readability and maintainability of code.
- Allows for dynamic binding, which allows the appropriate method to be invoked depending on the object's actual class at runtime.
- Makes it easier to develop generic code that can handle objects of diverse types by enabling objects to be treated as a single type.
- Can make it more challenging to comprehend how an object behaves, particularly if its code is complicated.
- Performance problems could result from this because polymorphic behavior could call for extra runtime calculations.
Comments
Post a Comment