Search All Articles Submit your Website or Blog to A New Internet Library
Friday, April 9, 2010
Difference Between Function Overloading and Overriding ?
Overloading means having functions with the same name but with different signature.Signature includes method name and Parameters. These functions can be part of base class or derived class.
Whereas Overriding means changing the functionality of a method without changing the signature. We can override a funtion in base class by creating a similar function in derived class and by use virtual/override keywords.
Base class method has to be marked with virtual keyword and we can override it in derived class using override keyword.
Derived class method will completly overrides base class method i.e when we refer base class object created by casting derived class object a method in derived class will be called.
Example:
Base Class:
-------------------------------
public class BaseClass
{
public virtual void Method1()
{
Print("Base Class Method");
}
}
Derived class
---------------
public class DerivedClass: BaseClass
{
public override void Method1()
{
Print("Derived Class Method");
}
}
Usage
--------------------------
public class Sample
{
public void TestMethod()
{
DerivedClass objDC = new DerivedClass();
objDC.Method1();
BaseClass objBC = (BaseClass)objDC;
objDC.Method1();
}
}
Result
---------------------
Derived Class Method
Derived Class Method
Also Read other Top Articles
- JSON Serialization in VS 2008
- Implementing Forms Authentication in Silverlight Application.
- Making GridView Rows or Individual Cells Clickable and Selectable.
- Enabling browser back button for GridView Paging and Sorting in Ajax 1.1 and 3.5 (using Visual Studio 2005/ Visual studio 2008)
- How to pass values from User Control to Page or calling Page methods from User Control.
- What is WCF?
- New features in C# 4.0
- C# to VB.NET and VB.NET to C# online free converter tools.


1 comments:
I constantly similar to interpret amazing love this.Thanks for this post.I have clearly in Difference Between Function Overloading and Overriding.
Post a Comment
Post your comments/questions/feedback for this Article.