Hi, my self Ravi Vishwakarma. I have completed my studies at SPICBB Varanasi. now I completed MCA with 76% form Veer Bahadur Singh Purvanchal University Jaunpur.
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);
} }
Liked By
Write Answer
Differentiate between overloading and overriding.
Join MindStick Community
You have need login or register for voting of answers or question.
Ashutosh Kumar Verma
26-Aug-2021Difference between Overloading and overriding-
Overriding