What is overloading and how can this be done ?




Answers were Sorted based on User's Feedback



What is overloading and how can this be done ?..

Answer / rashid

Overloading is the process of call the same method with
different parameter types,diferent order of parameters with
in the class.Its also applicable for the constructor.

here i give some example

class sample
{
public void display()
{
Console.WriteLine("display :1");
}
public void display(int i,int j)
{
int s=0;
s = i+j;
Console.WriteLine("Result :"+s);
}
}

class Overload
{
public static void Main(string []args)
{
sample s = new sample();
s.display();
s.display(5,5);
}

Is This Answer Correct ?    5 Yes 0 No

What is overloading and how can this be done ?..

Answer / mahesh babu ummaneni

overloading is nothing but method name is same but perameters is different.
for example
class overloading
{
public void add(int x)
{
console.writeline("sum");
}
public void add(int x,int y)
{
console.writeline("THE SUM IS:"+(x+y));
}
}

Is This Answer Correct ?    1 Yes 0 No

What is overloading and how can this be done ?..

Answer / rajesh

the above one is absolutely right

Is This Answer Correct ?    0 Yes 0 No




What is overloading and how can this be done ?..

Answer / senthil kumar

Overloading is the process of call the same method with
different parameter types,diferent order of parameters with
in the class.Its also applicable for the constructor.

here i give some example

class sample
{
public void display()
{
Console.WriteLine("display :1");
}
public void (int i,int j)
{
int s=0;
s = i+j;
Console.WriteLine("Result :"+s);
}
}

class Overload
{
public static void Main(string []args)
{
sample s = new sample();
s.display();
s.display(5,5);
}
}

Is This Answer Correct ?    0 Yes 4 No

Post New Answer



More C Sharp Interview Questions

Can I define my own exceptions?

0 Answers  


How?s method overriding different from overloading?

4 Answers  


What do you mean by synchronous and asynchronous operations?

0 Answers  


I created a class which is inherited from interface IDisposable. Now if I use object of this class with using keyword. Then How the dispose method will get call. Does garbage collector call it or some else.

2 Answers   Sapient,


Can you create partial delegates and enumerations?

0 Answers  






Give an example to show for hiding base class methods?

0 Answers  


I have 3 overloaded constructors in my class. In order to avoid making instance of the class do I need to make all constructors to private?

0 Answers  


What is a virtual property. Give an example?

0 Answers  


What is garbage collector and where should you use in .NET?

0 Answers   Siebel,


What is Inheritance in C#?

0 Answers   B-Ways TecnoSoft,


How to authenticate web service? When you enter the web service url in browser it should ask username and password. After entering the un&pwd we have to show its methods and service description(wsdl).

3 Answers  


Does c# support const methods, properties, or events?

0 Answers  






Categories