You need to include this Overloading functions in Our Class Named "emp" as shown below
class emp
{
int ts;
//I am creating three functions using same name
public void tsal(int sal)
{
MessageBox.Show(sal.ToString(),"Salary");
}
public void tsal(int sal,int bonus)
{
ts = sal + bonus;
MessageBox.Show(ts.ToString(),"Salar+Bonus is ");
}
public void tsal(int sal, int bonus, int ta)
{
ts = sal + bonus + ta;
MessageBox.Show(ts.ToString(),"Salary+Bonus+ta is ");
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
//I am calling three functions using button click event
private void button1_Click(object sender, EventArgs e)
{
emp e1 = new emp();
int s, b, t;
s = 5000;
b = 300;
t = 200;
e1.tsal(s);
e1.tsal(s,b);
e1.tsal(s,b,t);
}
Coming to the Output Use f5
You see a window as shown below
Click on Button
Output1
You see Salary=5000then click OK
Output2
You see Salary +Bonus =5300
Output3
You see Salary+Bonus+ta =5500
Got it?
To know about Operator Overloading Click Here
Subscribe to:
Post Comments (Atom)
Comments (0)
Post a Comment