What is polymorphism? What is difference between static binding and dynamic binding? Explain with the help of an example.
Polymorphism in the context of Object-Oriented Programming (OOP) refers to the ability of a single entity, such as a method or class, to take on multiple forms. It allows objects to be treated as instances of their parent class, enabling code to be more flexible, reusable, and extensible. Polymorphism is one of the four fundamental principles of OOP, along with encapsulation, inheritance, and abstraction.
There are two types of polymorphism in Java: compile-time (or static) polymorphism and runtime (or dynamic) polymorphism.
1. Static Binding (Compile-Time Polymorphism):
Static binding occurs at compile time and is also known as early binding. In this type of polymorphism, the method that needs to be executed is determined during the compile-time based on the method signature. It is associated with method overloading, where multiple methods with the same name exist in the same class, but with different parameter lists.
```java
________ ___ _____ ___ ___ _______.
_______ _______ ______ _____ ____ _______ __________.
________ ______ _______ ____ _____ _________ ______ ____.
________ ________ ________ ____ ________.
__________ _____ __________ __________ _______ _______ _______ ____ ___ ______ ________.
___ ________ __________ ______ _____ ______.
________ _______ __________ _______ ________ __________ _______.
___ __________ _____ ________ _________ _____ ___ __________.
_________ __________ ___ ____ ___ _______ ______ _______.
____ _________ ______ __________ __________ _________ ______ _________ ___ _____ __________.
______ _______ ____ ________ _________.
___ ________ ________ _____ _______ _____ _______ ________ __________ __________.
__________ _________ __________ _____ ___ ____ _______.
_________ ___ _____ ______ _________ ______ _____ ________ _______.
_______ ______ _________ ______ ____ _________.
___ ___ ___ ________ ______ ________ ________ ____.
______ ______ _________ __________ _______ _______ ___ _________.
_______ _____ ____ _______ __________ ____.
_____ ___ ________ ________ _____ _____ _______ __________ ______ _____ __________.
___ ____ _______ __________ ____ ________ _______ _________ ________ ___ ____ _________.
_________ ________ ________ ______ _______ ______.
____ ___ __________ ________ __________ _________.
________ _______ __________ _________ _______ __________ ______ ____ ____.
__________ _____ _________ __________ _________.
_______ _______ _______ ___ _____ ____ _________ __________ _______ ______ _____.
_________ _____ ___ _____ _____ ___ ___ __________ ____ ________.
________ ____ __________ ______ _________ ____ ________ ________ ___ _____.
_________ ____ __________ ____ ________ _________ _________ __________ _______ __________ ______.
_________ ________ ________ _______ ______.
_____ ___ ____ _____ _________.
________ _______ __________ __________ __________ ____ _________ __________.
_________ _______ ________ ___ ________ ___ ______ ________ ______ ___ _____ _____.
__________ ______ ______ _________ ______ _______ ___ __________ _____.
_____ ___ ______ _____ _____ _____ ________ _____ _______ ____ _____ __________.
____ ___ ___ ___ ______.
____ ___ _________ _______ _______ _______ _____ ____.
_________ _________ ___ _____ ______ _________ ______.
___ ___ _______ _______ ___ _____ ____ ____ _____.
___ __________ ___ ____ _______.
_______ ________ ___ ____ ______ ________ ____ ______ _________ __________ ______ _______.
________ _____ __________ _____ ______ _____.
________ ___ ____ __________ _______ ___ _______ __________ _______.
__________ ___ _____ ________ ________ ______ _____.
_________ _________ ___ _________ _________ ______ ___ _________ ________.
_______ _________ ______ _____ ____.
________ ______ _______ ______ _________ ________ ______.
______ ___ _________ ________ ________.
_____ ____ _________ _______ ________ _____ __________.
_____ __________ _____ ______ __________ _________ ____ ______ _________.
____ ________ _____ __________ _____ _____ ________.
_________ ________ _________ ________ _______ __________ ____ _____ _________ _______ ____ ________.
______ ___ _____ ___ _______ _______ __________.
________ _________ ________ ______ _________ ______ ___ ____.
_______ _____ ________ __________ ____.
____ ______ ___ _____ _________ ______ ___ _____ ______.
_________ _______ ________ ___ _____ ___ _____ ________ _______.
______ ___ _______ _________ ______.
Get Full Answer on WhatsApp