Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Difference between overloading and overriding in JAVA

    • 0
    • 1
    • 1
    • 1
    • 0
    • 0
    • 0
    • 0
    • 328
    Comment on it

    Hi,

    Difference between overloading and overriding in java is a repeatedly asked and very important interview question. So, you can find the details over here.

    1. Method overloading in JAVA is used to increase readability of program while method overriding is used to provide specific implementation of a method already defined in super class.
    2. Overloading is done within a class but method overriding is used within two classes in which inheritance is implemented.
    3. Method overloading is an example of compile time polymorphism while overriding is an example of run time polymorphism.
    4. Parameter differs in overloading while parameter's and its type always remains same in overriding.

    Overloading Example

        class A {  
            static int add(int a, int b) {
                 return a+b;
            }  
            static int add(int a, int b, int c) {
                return a+b+c;
            }  
        }  
    

    Overriding Example

        class A {  
             void myFunction(){
                  System.out.println("parent function...");
             }  
        }  
        class B extends A {  
             void myFunction() {
                  System.out.println("child function...");
             }  
        }  
    
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: