polymorphism in java

radha gogia

radha gogia

@radha-BTDzli Oct 24, 2024
I just have a little confusion that regarding polymorphism that is method overloading and overriding really a part of polymorphism becoz somewhere I get to know that method overloading is compile-time polymorphism and somewhere i read that overloading and overriding is actually not at all a part of polymorphism,so plz clarify the distinction that is it really that method overloading and overriding are a part of polymorphism or not.

Replies

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform

  • Anoop Kumar

    Anoop Kumar

    @anoop-kumar-GDGRCn Oct 13, 2014

    Yes.. Method overloading is compile time as we are passing different argument.
     public void getEmpName(int empId) {
        ......
    }
    
    public void getEmpName(String empName) {
        ......
    }
    
    public void getEmpName(int empId, String empName) {
        ......
    }
    and in method overriding is same signature from parent and subclass. so, if you use interface based programming while execution only it will be decided as runtime.

    Now coming to your question, I see stackoverflow discussion but IMO overloading is polymorphism. If you see the implementation of System.out.println method there are 10 implementation. Now as a user just use the method and compare with the definition of polymorphism. If it is fulfilling the criteria then yes, overloading is a polymorphism.
     polymorphism means that some code or operations or objects behave differently in different contexts.
    #-Link-Snipped-#.
    Some say overloading is ad-hoc but as per definition, if code is behaving differently at different scenario then its polymorphism.
  • micheal john

    micheal john

    @micheal-john-l1fIn3 Oct 14, 2014

    Method overload is compile time and
    Method overriding is run-time polymorphsim