Interview Question
Qus: Explain about the method overloading.
Public class Mycalcuation
{
Private int a;
Private int b;
Private int c;
Public int Add(int a,int b)
{
Return a+b;
}
Public int Add(int a,int b,int c)
{
Return a+b+c;
}
}
Static void Main()
{
MyCalculation objCalc= new MyCalculation();
ObjCalc.Add(2,3)
// It will call first method Add which has two argument
ObjCalc.Add(2,3,4)
// It will call Second method Add which has
three argument eventhough it has same name
}
Answers (2)
{
Private int a;
Private int b;
Private int c;
Public int Add(int a,int b)
{
Return a+b;
}
Public int Add(int a,int b,int c)
{
Return a+b+c;
}
}
Static void Main()
{
MyCalculation objCalc= new MyCalculation();
ObjCalc.Add(2,3)
// It will call first method Add which has two argument
ObjCalc.Add(2,3,4)
// It will call Second method Add which has
three argument eventhough it has same name
}