Method OverLoading
Asp.Net sample projects
Method OverLoading
Method Overloading source code in C# asp.net
In Method Overloading one method can be used for two different Datatypes Int,Double.
Method OverLoading is Compile Time Polymorphism.
Polymorphism is an Object Oriented Programming Concept in which same operation may behave differently on different classes.
///////////////////////MethodOverloadclass.cs/////////////////////////////////////
Method OverLoading
Method Overloading source code in C# asp.net
In Method Overloading one method can be used for two different Datatypes Int,Double.
Method OverLoading is Compile Time Polymorphism.
Polymorphism is an Object Oriented Programming Concept in which same operation may behave differently on different classes.
///////////////////////MethodOverloadclass.cs/////////////////////////////////////
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MethodOverloading
{
class MethodOverloadclass
{
public int Add(int a, int b)
{
int c;
c = a + b;
return c;
}
public int Add(int a, int b, int c)
{
int d;
d = a + b + c;
return d;
}
public static void Add(double x, double y, double p, double q)//Word Static says no need to create an object.
//directly call method by class reference.
{
double z;
z = x + y + p + q;
Console.WriteLine("Addition of 4 nos is: " + z);
}
}
}
--------------------------------------------------------------------------------------------------------------------
////////////////////
Program.cs////////////////////////////////
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MethodOverloading;
namespace MethodOverloading1
{
class Program
{
static void Main(string[] args)
{
MethodOverloadclass obj = new MethodOverloadclass();
Console.WriteLine("This is a program of Method OverLoading which uses Polymorphism");
Console.WriteLine("Here we added 2 nos and 3 nos and 4 nos with same Method defined as Add.");
Console.WriteLine("Addition of 2 nos is: " + obj.Add(2,2));
Console.WriteLine("Addition of 3 nos is: " + obj.Add(2, 2, 2));
MethodOverloadclass.Add(10,10,10,10);
}
}
}
No comments:
Post a Comment