What is Interface Polymorphism?with E.g

Answer Posted / sandeep negi

//Consider IShape interface like this

interface IShape
{string CalculateArea();}

class Circle : IShape
{
public string CalculateArea(){return "Circle area";}
}

class Rectangle : IShape
{
public string CalculateArea(){return "Rectangle
area";}
}


//implement function
private string ProcessArea(IShape shape)
{return shape.CalculateArea();}

//call this function from main or from button click event
like this

private void button1_Click(object sender, EventArgs e)
{
Rectangle r = new Rectangle();
Circle c = new Circle();
MessageBox.Show(ProcessArea(r));
MessageBox.Show(ProcessArea(c));
}

Is This Answer Correct ?    3 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can You Prevent Your Class From Being Inherited By Another Class?

720


How many constructors can a class have in c#?

666


What is console based application?

701


Is c# and .net same?

642


What are strong name assemblies?

742


What is a .aspx file?

624


How can you reference current thread of the method ?

696


What is assembly version series sequence?

721


Is datetime immutable c#?

669


What are the commonly used i/o classes?

720


What can be done with c#?

605


How to find the current application file path while runtime?

691


What is a partial class. Give an example?

684


How do I unload an application domain?

695


The int maps to which C# keyword in .NET type?

833