Tuesday, January 03, 2012

What is the Difference between Overriding and overloading?

Posted by Rahul Kharde at 12:58 AM
Overloading is defining functions that have similar signatures, yet have different parameters. 

Overriding is only pertinent to derived classes, where the parent class has defined a method and the derived class wishes to override that function.

Overriding
Overloading
Methods name and signatures must be same.
Having same method name with different
Signatures.
Overriding is the concept of runtime polymorphism
Overloading is the concept of compile time polymorphism
When a function of base class is re-defined in the derived class called as Overriding
Two functions having same name and return type, but with different type and/or number of arguments is called as Overloading
It needs inheritance.
It doesn't need inheritance.
Method should have same data type.
Method can have different data types
Method should be public.
Method can be different access specifies

Example

Overriding

public class MyBaseClass
{
    public virtual void MyMethod()
    {
        Console.Write("My BaseClass Method");

    }
}
public class MyDerivedClass : MyBaseClass
{
    public override void MyMethod()
    {
        Console.Write("My DerivedClass Method");

    }
}

Overloading 

int add(int a, int b)
int add(float a , float b)



If you enjoyed this post and wish to be informed whenever a new post is published, then make sure you subscribe to my regular Email Updates. Subscribe Now!


Kindly Bookmark and Share it:

YOUR ADSENSE CODE GOES HERE

13 comments:

Nanil on February 6, 2013 at 7:53 PM said...

thank you sir. its enough to understand


Anonymous said...

nice and simple article thanks


mohit sharma on March 22, 2013 at 4:33 AM said...

thanks for helping me to clear this topic..


raghu said...

nice article


lingmaaki on January 18, 2015 at 11:44 PM said...

Check this one.....Difference between method overloading and method overriding

Ling


ajmath shaik on March 27, 2015 at 2:05 AM said...

Excellent explanation Difference Between Method Overloading and Method Overriding


satish dixit on November 1, 2015 at 3:28 AM said...
This comment has been removed by the author.

satish dixit on November 1, 2015 at 3:29 AM said...

nice post .refer simillar post What is Function Overriding and Function Overloading in Java


Hitesh Kumar on July 14, 2016 at 1:32 AM said...

Difference Between Overloading and Overriding in Java

Nice Article Thanks for sharing this post


Dipendra Karki on July 23, 2016 at 8:46 AM said...

thank you for this answer


Dhanraj Sakariya on August 18, 2016 at 5:08 AM said...

sorry sir, but i need more difference. means more line.


J.Nageswara Rao on September 27, 2016 at 6:46 AM said...

ok so nice
please provide additional information about c++


Geetha Devi on January 28, 2017 at 2:14 AM said...

Thanks for sharing overriding and overloading concepts in java..java training in chennai


Have any question? Feel Free To Post Below:

 

Popular Posts

Recent Comments

© 2011. All Rights Reserved | Help to understand .Net | Template by Blogger Widgets

Home | About | Top