Runtime polymorphism

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
A objA = new A();
B objB = new B();
sendmsg(objA);
sendmsg(objB);
Console.ReadLine();
}
public static void sendmsg(imsg objmsg)
{
objmsg.displaymessage();
}
}

interface imsg
{
void displaymessage();
}
class A : imsg
{
public void displaymessage()
{
Console.WriteLine("this is class A displaymsg()");
}
}

class B : imsg
{
public void displaymessage()
{
Console.WriteLine("this is class B displaymsg()");
}
}
}

0 comments: