GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

GeekInterview.com  >  Tech FAQs  >  Programming  >  C#
Go To First  |  Previous Question  |  Next Question 
 C#  |  Question 27 of 40    Print  
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 .



  
Total Answers and Comments: 2 Last Update: July 11, 2008     Asked by: aarruunnaa 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
December 04, 2007 01:34:16   #1  
kiran prasad Member Since: October 2007   Contribution: 7    

RE: C# Error - Overload for method
you are getting error because when you create a subclass object, it automatically calls up the base class constructor.

You need to provide a default constructor(no argument constructor) for the base class i.e emp class to get rid off that error.


You can take user inputs using text boxes on your form.

 
Is this answer useful? Yes | No
July 11, 2008 02:02:49   #2  
sudhakarr.net Member Since: July 2008   Contribution: 8    

RE: C# Error - Overload for method
Hi aarruunnaa,
You try this code, if it is useful for you send me reply otherwise ask me again dont hesitate 
class emp

{

public int eno,sal;

public emp(){}

public emp(int eno,int sal)

{

this.eno=eno;this.sal=sal;

}

public virtual void print()

{

MessageBox.Show("eno = " + eno.ToString() + " sal " + sal.ToString());

}

}

class bonus : emp

{


public int bon,ts;

public bonus(){}

public bonus(int bon,int eno,int sal):base(eno,sal)

{

this.bon=bon;

}

public override void print()

{

base.print();

ts=bon+sal;

MessageBox.Show("ts = " + ts.ToString());

}

}
private void button1_Click(object sender, System.EventArgs e)

{

DialogResult dr;

dr = MessageBox.Show ("r u giving bonus", "peers", MessageBoxButtons.YesNo, MessageBoxIcon.Information);

if (dr == DialogResult.Yes)

{

bonus obj = new bonus(3000,101,5000);

obj.print();

}

else

{

emp x =
new emp(101,5000);

x.print();

}



}
Thanks,
sudhakar


 
Is this answer useful? Yes | No

 Related Questions

I have a class with constructor, if i throw an error inside the constructor what will become the object while initializing
Read Answers (1) | Asked by : Febin

Interface contains the declaration of methods only and we can declare this method also inside our own class.So what is the need once declare a method inside the interface and then implement it into a class?
Read Answers (1) | Asked by : amitdwi

A=(5>6)8:10Consol.Writeline(a);please tell me the output of this statementit is conditional statement .the result is error or give 8 as a result?

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 
Latest Answer : Hi aarruunnaa,You try this code, if it is useful for you send me reply otherwise ask me again dont hesitate class emp {public int eno,sal; public emp(){}public emp(int eno,int sal) {this.eno=eno;this.sal=sal; }public virtual void print() {MessageBox.Show("eno ...


 Sponsored Links

 
Related Articles

Concepts of Object-Oriented Programming

Object Oriented JavaScript In this chapter you ll learn about OOP Object Oriented Programming and how it relates to JavaScript As an ASP NET developer you probably have some experience working with objects and you may even be familiar with concepts such as inheritance However unless you re already a
 

What is Common Data Modeling Method

Common Data Modeling is one of the core considerations when setting up a business data warehouse. Any serious company wanting to have a data warehouse will have to be first serious about data models. Building a data model takes time and it is not unusual for companies to spend two to five years just
 

SQL Programming

SQL Programming Overview Anybody who has done something for a long time has probably wanted to change how things work at some point or another. A worker at a mill might have found a more efficient way of cutting logs, or a mathematics teacher might have had a hand in changing a school’s al
 

WinRunner Programming Concepts

If you want to create WinRunner scripts that are highly efficient, there are important programming concepts that you will want to become familiar with. Understanding these concepts will provide you with a large number of key benefits. In addition to understanding these concepts, you must also learn
 

Programming Languages Certification

IT Certification programs have several options that will offer you the best knowledge.  By learning everything that you need to know about information technology you will be able to open new doors to your career and personal business desires.  IT Certification offers several vari
 

JavaScript Window Object Open Method Part 2

JavaScript Window Object Open Method Part 2 In this JavaScript tutorial you will learn about JavaScript Window Object Open Method features of window object open method scrollbars status titlebar toolbar top width innerHeight innerWidth outerHeight outerWidth and hotkeys mosgoogle center scrollbars S
 

JavaScript Window Object Open Method

JavaScript Window Object Open Method In this JavaScript tutorial you will learn about JavaScript Window Object Open Method features of window object open method channelmode directories dependent fullscreen screenX screenY height left location menubar resizable alwaysLowered alwaysRaised mosgoogle ce
 

Neuro-linguistic Programming Methods

Neuro linguistic Programming Methods There are several methods used for performing Neuro linguistic Programming on an individual for obtaining insights into the psyche of the person in order to correct to modify certain patterns of behavior These techniques are also used for Neuro linguistic trainin
 

The Difficult Past of Neuro-linguistic programming

The Difficult Past of Neuro linguistic programming Neuro linguistic programming has had a rocky past with a number of lawsuits rivalry unsystematic development and intermittent progress During the 1980s the two founders separated after the lawsuit filed by Bandler Bandler went on to file several law
 

History of Neuro Linguistic Programming (NLP)

History of Neuro linguistic programming Neuro Linguistic Programming NLP is a system co founded by John Grinder and Richard Bandler for bringing about personal development in any individual by interpreting and translating the human perception experience beliefs and language It was developed in early
 





About Us  |   Privacy Policy  |   Terms and Conditions  |   Contact  |   Site Map  |   Add Question  |   Propose Category  |   RSS Feeds  |   Articles Sitemap  |   Site Updates  |   Add Resource

Copyright © 2005 - 2008 GeekInterview.com. All Rights Reserved
Page copy protected against web site content infringement by Copyscape