Polymorphism means same method playing different roles for different requirements at the same time. For example, Father plays a role of son for his father and at the same time he plays the role of father for his son.
namespace Polymorphism
{
class Program
{
public void Bank()// Defining Bank function without any Parameters
{
Console.WriteLine("You have successfully opened an account");
}
//Defining Bank method with two Parameters
public void Bank(int Credit, int Deposit)
{
int c = Credit;
int d = Deposit;
Console.WriteLine("Credit: " + c + " Deposit: " + d);
}
//Defining Bank method with return type and single parameter
public string Bank(string Msg)
{
string msg = Msg;
return msg;
}
static void Main(string[] args)
{
Program obj = new Program();//Instantiating Program class
//Calling more than one method named Bank at the same time
obj.Bank();
obj.Bank(4500, 2200);
Console.WriteLine(obj.Bank("Your account has been credited with Rs. 4500"));
Console.ReadLine();
}
}
}
Join MindStick Community
You need to log in or register to vote on answers or questions.
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.
Polymorphism means same method playing different roles for different requirements at the same time. For example, Father plays a role of son for his father and at the same time he plays the role of father for his son.