What is the difference between OVERRIDING and OVERLOADING

Showing Answers 1 - 16 of 16 Answers

Hari

  • May 9th, 2005
 

Overriding - same method names with same arguments and same return types associated in a class and its subclass. 
 
Overloading - same method name with different arguments, may or may not be same return type written in the same class itself.

  Was this answer useful?  Yes

varsha

  • Jun 13th, 2005
 

Ya.. u can also sau that Overloading is static Polymorphism and Overridding is dynamic polymorphism.

Sony

  • Jul 3rd, 2005
 

the best answer is that both overloading and over-riding are different aspects of polymorphism.......;-) 
 
static/early binding polymorphism:overloading 
dynamic/late binding polymorphism:overriding 

Jayaprabhakar

  • Feb 7th, 2007
 

Overloading is compile time binding, where as overriding is dynamic binding.A good example that differentiates between overloading and overriding is shown here.
overriding is compile time binding

  Was this answer useful?  Yes

ramana

  • Oct 6th, 2007
 

Please clarify the difference
class A
{
void calc()
{
}
int calc(int)
{
}
}
class B:public  A
{
void calc()
{
}
}

This is just an abstract of the program.
If we have a program like this and an object of class B is created and we call b.calc will the compiler first call the method calc of super class or sub class?
What will be the effect of virtual key word on this program?
Is the calc function over loaded?
Can we say this as an example for over riding?

  Was this answer useful?  Yes

Blah

  • Oct 11th, 2007
 

Please clarify the difference
class A
{
void calc()
{
}
int calc(int)
{
}
}
class B:public  A
{
void calc()
{
}
}

This is just an abstract of the program.
If we have a program like this and an object of class B is created and we call b.calc will the compiler first call the method calc of super class or sub class?
What will be the effect of virtual key word on this program?
Is the calc function over loaded?
Can we say this as an example for over riding?

-------------------------------------------------------------------------
In this case, when class B calls a.calc the complier will first look at the signature of calc. Class B needs to either call a.calc() or a.calc(int).

  Was this answer useful?  Yes

Anil Singh

  • Feb 18th, 2009
 

Overloading: Methods name same but signatures is different in the class.

Example:

class b{
   
    public void add(int i,int j){
       int n=i+j;
       System.out.println(n);
    }
    public void add(int i,int j,int k){
       int n=i+j+k;
       System.out.println(n);
    }
    public void add(int i,int j,int k,int l){
      int n=i+j+k+l;
      System.out.println(n);
    }
    public static void main(String []aa){
     b b1=new b();
     b1.add(1,2,5);
    }
}
output: 8

Overriding:To redefine the base class method in the derived class is called overriding.

Example:
        
  class a{
   
       public void display(){
                        System.out.println("it is a firest class method");
      }
  }
class overiding extends a{
   
    public void display(){
              System.out.println("it is a Second class method");
    }
     public static void main(String []anil){
        overiding obj=new overiding();

        obj.display();
     
    }
}
output:  it is a Second class method

Overloading: The methods with the same name but it differs by types of guments and number of arguments.

Overriding:  The methods with the same name and same number of arguments and types but one is in base class and second is in derived class.

kamesh23

  • Jun 12th, 2009
 

OvERLOADING:  Same function with different arguments
                             ADDITION(int x,int y)                               ADDITION(int x ,int y,int z)
                              {                                                             {
                                  -------------------------                                ---------------
                                 --------------------------                               -------------------
                               }                                                             }
OVERRIDING: Same function with same arguments
                          
                             ADDITION(int x,int y)                               ADDITION(float x ,float y)
                              {                                                             {
                                  -------------------------                                ---------------
                                 --------------------------                               -------------------
                               }                                                             }

  Was this answer useful?  Yes

Overriding refers to a situation where a sub-class inherits a method from a super class which may result into adding or changing the methods behaviour while overloading refers to a situation where there are two or more methods in a class with the same name but with different parameter lists.

  Was this answer useful?  Yes

Difference between Overriding and Overloading
(1) Def. (Overloading) : Two or more function have same name but differ with parameter passed or return type.
Def. (Overridding) : Super class method redefine in sub class with same prototype that is called Overriding
(2) Overloading is not related with inheritance, while overriding is related with inheritance. means without inheritance overriding is not possible but overloading is possible

  Was this answer useful?  Yes

PraveenkumarJ

  • Aug 25th, 2011
 

OVERRIDING..........
Overriding is which is having the same method name, parameter, and return type but must be in different class
Overriding example code

Code
  1. class A

  2. {

  3. public void jpr();

  4. {

  5. Sytem.out.println("Have a cup of coffee");

  6. }

  7. }

  8. class B extends A

  9. {

  10. public void jpr();

  11. {

  12. System.out.println("Have 2 cup of coffee");

  13. }

  14. public static void main (String args[])

  15. {

  16. B ob=new B();

  17. ob.jpr();

  18. }

  19. }

  Was this answer useful?  Yes

harish

  • Sep 8th, 2011
 

overloading:in this case method name is same with different arguments and should be defined within the class for ex:
class A
{
void sum()
{

}
void sum(int a)
{

}
}
over riding:in this case method name is same with same arguments i.e name of the method and arguments should be same in both base class and derived class
for ex:
class A
{
void sum(int a)
{

}
}
class B extends A
{
void sum(int a)
{

}
}

  Was this answer useful?  Yes

Meher

  • May 29th, 2012
 

Overloading and overriding are different aspects of polymorphism.
Overloading is also called static/early binding polymorphism.
Overriding is also called dynamic/late binding polymorphism.

  Was this answer useful?  Yes

k.samba

  • Feb 4th, 2014
 

overloading is not related with inheritance that mean what

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

Answer Question

Click here to Login / Register your free account


 
Send   Reset

 

Related Answered Questions

 

Related Open Questions