You are on page 1of 4

using System;

//Method Overloading----Same Class Same funtion With Different Argument list....


namespace Polymorphism_Demo
{
class ComipleDemo
{
public int Add(int a,int b)
{
return (a + b);
}
public double Add(double a, double b)
{
return (a + b);
}
public float Add(float a, float b)
{
return (a + b);
}

}
class Program
{
static void Main(string[] args)
{
ComipleDemo c1 = new ComipleDemo();
double a=c1.Add(12.44,23.55);
Console.WriteLine(a);
Console.Read();
}

Construcotr Overloading

using System;
//Constructor Overloading----Same Class Same funtion With Different Argument list....
namespace Polymorphism_Demo
{
class Employee
{
int salary;
public Employee()
{
salary = 10000;
}
public Employee(int s)
{
salary = s;
}
public void Show()
{
Console.WriteLine("Salary=" + salary);
}
}
class Program
{
static void Main(string[] args)
{
Employee e = new Employee();
e.Show();
Employee e1 = new Employee(30000);
e1.Show();

}
}

Console.Read();

Operator Overloading

using System;
//Method Overloading----Same Class Same funtion With Different Argument list....
namespace Polymorphism_Demo
{
class Employee
{
int salary;
public Employee()

salary = 10000;
}
public Employee(int s)
{
salary = s;
}
public void Show()
{
Console.WriteLine("Salary=" + salary);
}
public static Employee operator +(Employee e1, Employee e2)
{
Employee e3 = new Employee();
e3.salary = e1.salary + e2.salary;
return e3;
}
public static Employee operator +(Employee e, int b)
{
Employee e1=new Employee();
e1.salary = e.salary + b;
return e1;
}

class Program
{
static void Main(string[] args)
{

}
}

Employee e = new Employee();


// e.Show();
Employee e1 = new Employee(30000);
// e1.Show();
Employee e3 = new Employee(30000);
Employee e5 = new Employee(30000);
//e3.Show();
Employee e4 = e + e1+e3+e5;
Employee e6 = e+e3 + 1000;
e6.Show();
e4.Show();
Console.Read();

Method Overridng
using System;

//Method Overloading----Same Class Same funtion With Different Argument list....


namespace Polymorphism_Demo
{
class Parent
{
public virtual void Show(int a)
{
Console.WriteLine("Parent" + a);
}
}
class Child:Parent
{
public override void Show(int a)
{
Console.WriteLine("Child" + a);
}
public void Show2()
{
Console.WriteLine("Child Show2");
}
}
class Program
{
static void Main(string[] args)
{
// Parent p = new Parent(); //Static Binding
// p.Show(45);
//Child cl = new Child();
// cl.Show(12);
Parent p = new Parent(); //Dynamic Binding
p.Show(10);
p = new Child();
p.Show(23);

}
}

Console.Read();

You might also like