Wednesday, April 27, 2011

What is Overloading and Overriding

Overloading - is the concept of using one function or class in different ways by changing the signature of its parameters. We can define a function with multiple signatures without using the keyword Overloads, but if you use the Overloads keyword in one, you must use it in all of the function's Overloaded signatures.

The Overloads keyword is used in VB.NET, while the Overload keyword is used in C# (There is no other difference). The Overloads property allows a function to be described using deferent combinations of parameters. Each combination is considered a signature, thereby uniquely defining an instance of the method being defined.

Overloading is a way through which polymorphism is achieved.

Overloading

Overloading is when you have multiple methods in the same scope, with the same name but different signatures.

//Overloading

public class test

{

public void getStuff(int id)

{}

public void getStuff(string name)

{}

}

Overriding

Overriding is a principle that allows you to change the functionality of a method in a child class.

//Overriding

public class test

{

public virtual getStuff(int id)

{

//Get stuff default location

}

}



public class test2 : test

{

public override getStuff(int id)

{

//base.getStuff(id);

//or - Get stuff new location

}

}

No comments:

Post a Comment