C# Error - Overload for method
I took a button in form.
I have two classes emp and bonus.bonus class is inherited from emp class.
If bonus is giving ie in dialog box if we select ‘Yes’ b ie bonus is added to sal and we get ts ie total sal along with eno.
If bonus is not given ie in dialog box if we select ‘No’ we need to get only sal along with eno.
The following pgm is working fine.
class emp
{
private int eno = 101;
protected int sal = 5000;
public void print()
{
MessageBox.Show("eno = " + eno.ToString() + " sal " + sal.ToString());
}
}
class bonus : emp
{
int b, ts;
public void increment (int x)
{
b = x;
print();
ts = sal + b;
MessageBox.Show("ts =" + ts.ToString());
}
}
private void button1_Click(object sender, EventArgs e)
{
DialogResult dr;
dr = MessageBox.Show ("r u giving bonus", "peers", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
if (dr == DialogResult.Yes)
{
bonus obj = new bonus();
obj.increment(3000);
}
else
{
emp x = new emp();
x.print();
}
}
}
But I want to give values as parameters
So I wrote the pgm as
class emp
{
private int eno;
protected int sal;
public emp(int x, int y)
{
eno = x;
sal = y;
}
public void print()
{
MessageBox.Show("eno =" + eno.ToString() + "sal = " + sal.ToString());
}
}
class bonus : emp
{
private int b, ts;
public bonus(int z)
{
b = z;
//}
int ts;
ts = b + sal;
print();
MessageBox.Show("ts = " + ts.ToString());
}
}
private void button1_Click(object sender, EventArgs e)
{
DialogResult dr;
dr = MessageBox.Show("are u giving bonus", "peers", MessageBoxButtons.YesNo, MessageBoxIcon.None);
if (dr == DialogResult.Yes)
{
emp x1 = new emp(101,5000);
bonus obj = new bonus(3000);
x1.print();
}
else
{
emp x = new emp(101,5000);
x.print();
}
}
}
Now Iam getting error as No overload for method 'emp' takes '0' arguments .How to solve this error
Actually my intension was to ask eno,sal and bonus at runtime and display the results accordingly when I press button which I took in form .how to ask them at runtime .
Can u give me that code .
Questions by aarruunnaa answers by aarruunnaa
Showing Answers 1 - 6 of 6 Answers
Related Answered Questions
Related Open Questions
C# Error - Overload for method
I have two classes emp and bonus.bonus class is inherited from emp class.
If bonus is giving ie in dialog box if we select ‘Yes’ b ie bonus is added to sal and we get ts ie total sal along with eno.
If bonus is not given ie in dialog box if we select ‘No’ we need to get only sal along with eno.
The following pgm is working fine.
class emp
{
private int eno = 101;
protected int sal = 5000;
public void print()
{
MessageBox.Show("eno = " + eno.ToString() + " sal " + sal.ToString());
}
}
class bonus : emp
{
int b, ts;
public void increment (int x)
{
b = x;
print();
ts = sal + b;
MessageBox.Show("ts =" + ts.ToString());
}
}
private void button1_Click(object sender, EventArgs e)
{
DialogResult dr;
dr = MessageBox.Show ("r u giving bonus", "peers", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
if (dr == DialogResult.Yes)
{
bonus obj = new bonus();
obj.increment(3000);
}
else
{
emp x = new emp();
x.print();
}
}
}
But I want to give values as parameters
So I wrote the pgm as
class emp
{
private int eno;
protected int sal;
public emp(int x, int y)
{
eno = x;
sal = y;
}
public void print()
{
MessageBox.Show("eno =" + eno.ToString() + "sal = " + sal.ToString());
}
}
class bonus : emp
{
private int b, ts;
public bonus(int z)
{
b = z;
//}
int ts;
ts = b + sal;
print();
MessageBox.Show("ts = " + ts.ToString());
}
}
private void button1_Click(object sender, EventArgs e)
{
DialogResult dr;
dr = MessageBox.Show("are u giving bonus", "peers", MessageBoxButtons.YesNo, MessageBoxIcon.None);
if (dr == DialogResult.Yes)
{
emp x1 = new emp(101,5000);
bonus obj = new bonus(3000);
x1.print();
}
else
{
emp x = new emp(101,5000);
x.print();
}
}
}
Now Iam getting error as No overload for method 'emp' takes '0' arguments .How to solve this error
Actually my intension was to ask eno,sal and bonus at runtime and display the results accordingly when I press button which I took in form .how to ask them at runtime .
Can u give me that code .
Profile Answers by aarruunnaa Questions by aarruunnaa
Questions by aarruunnaa answers by aarruunnaa
Related Answered Questions
Related Open Questions