In case of method overloading there are two or more methods with same name in single class.
In Overriding all methods have also same name but in different classes.
There are different parameters passes in all same name methods.
There are same parameter passes in all methods.
In method overloading we can call all methods by a single instance of a class
Here all methods can call with different class instance.
It is call automatically suitable methods by passing argument.
In method overriding all parameters are same so we need to call them with different class instance.
Here all parameters are different in sequence, in types or in number of parameters.
Here all parameters are same in sequence ,in types and in number of parameters.
class Demo
{
public void Test(string name)
{
Console.WriteLine('Your name is'+name);
}
public void Test(int age)
{
Console.WriteLine('your age is'+age);
}
public void Test(string name, int age)
{
Console.WriteLine('your name is '+name+' and your age is '+age);
}
}
class OverloadingExp
{
static void Main(string[] arg)
{
Demo demo = new Demo();
demo.Test('Ashutosh \n');
demo.Test(24+'\n');
demo.Test('Ashutosh',24);
} }
public class Examp
{
public void Task(string name, int id)
{
Console.WriteLine('Name:{0}',name +' Id: '+ id);
}
}
public class Exp
{ public void Task(string name, int id)
{
Console.WriteLine('Name:{0}',name + 'Id: '+id);
}
}
public class Mark
{
public void Task(string name, int id)
{
Console.WriteLine('Name:{0}',name + 'Id: '+ id);
}
}
class OverridigExp
{
static void Main(string[] arg)
{
Examp exe = new Examp();
exe.Task('Examp',001);
Exp exp = new Exp();
exp.Task('Exp ' ,002);
Mark mark = new Mark();
mark.Task('Mark ', 003);
} }
Markdown for AI
A clean, structured version of this page for AI assistants and LLMs.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
Difference between Overloading and overriding-
Overriding