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 comment

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

Design a site like this with WordPress.com
Get started