3. Introduction to overloading
Method Overloading 3tMyn
Overloading allows functions in computer
languages such as C++ and C# to have the same
function name but with different parameters.
Overloading comes under static polymorphism.
Static polymorphism can be achieved within the
class.
4. The number of parameters and data type
of parameters must be different.It is showm
in the following example.
Example:
Add()
Add(int i)
Add(int i,int j)
Add(int i,double j)
Add(double i,double j)
Method Overloading tMyn 4
5. Method overloading
The process of creating more than one method in
a class with same name or creating a method in
derived class with same name as a method in
base class is called as method overloading.
In VB.net when you are overloading a method of
the base class in derived class, then you must use
the keyword “Overloads”.
But in C# no need to use any keyword while
overloading a method either in same class or in
derived class.
Method Overloading tMyn 5
6. While processing overloading methods, a
rule must be follow i.e, the overloaded
methods must differ either in number of
arguments they take or the data type of at
least one argument
Method overloading is commonly used to
create several methods with the same
name that perform the same or similar
tasks, but on different types or different
numbers of arguments.
6
11. The compiler distinguishes overloaded methods by their
signature :
A combination of the method’s name ,data types and
order of its parameters.
If the compiler looked only at method names during
compilation, the code in previous example would be
ambiguous.
Overloaded method calls cannot be distinguished by
return type.
11