Runtime polymorphism

Bellow Article Explain how you can achieve Run-time Polymorphism

 using System;  
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Runtime_polymorphism
{
class Program
{
static void Main(string[] args)
{
/* Testing Polymorphism */
Shape[] s = new Shape[3];
/* Polymorphic Objects */
/* creating Array with Different types of Objects */
s[0] = new Circle();
s[1] = new Ractangel();
s[2] = new Traingle();
Console.WriteLine("\n\nRuntime polymorphism test\n\n");
for (int i = 0; i < 3; i++)
{
s[i].Draw();
}
Console.ReadKey();
}
}
-------------------------------------------------------------------------------------------------------------
class Shape
{
public virtual void Draw()
{
}
}
-------------------------------------------------------------------------------------------------------------
class Ractangel : Shape
{
public override void Draw()
{
Console.WriteLine("Rectangle Drawn ");
}
}
--------------------------------------------------------------------------------------------------------------
class Circle : Shape
{
public override void Draw()
{
Console.WriteLine("Circle Drawn ");
}
}
-------------------------------------------------------------------------------------------------------------
class Traingle : Shape
{
public override void Draw()
{
Console.WriteLine("Triangle Drawn ");
}
}
}

Published by Nirbhay

Technology Geek,Blogger,Reviewer

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: