Basics of Java Polymorphism

Java Polymorphism


         Before starting this blog topic, first we want to know about some other things in java.   

      • Overriding 
      • Casting     
        You can get basic knowledge about that things using bellow blogger links.

Polymorphism:-

    After overriding a method of a parent class to the child class, the process of upcasting and calling a method of the child class through a parent class reference is called as polymorphism.

    Method Overloading allows a class to have multiple methods with the same name but different parameters (number, type, or order).

    

Types of polymorphism:-



  • Compile-time polymorphism- It is also known as static polymorphism. This type of polymorphism is achieved by method overloading or operator overloading. Java does not support operator overloading. Method overloading can occur in the same class or in a subclass.
  • Run-time polymorphism- Its called as method overriding. Method Overriding allows a subclass to provide a specific implementation of a method that is already defined in its superclass.
    
    In summary, polymorphism in Java enhances code reusability, flexibility, and maintainability. It allows for the creation of robust and extensible software systems by providing a mechanism for writing code that can work with objects of multiple types, promoting a more modular and organized approach to programming.

Meaningless Method:- 



  In meaningless methods, there are no any codes in the method body. We can use meaningless methods in method overloading.  

Example Polymorphism code:-


Comments

Post a Comment

Popular posts from this blog

අද අපි කතා කරමු Data collections ගැන

Understanding and Mastering Coding Errors

OOP key points