What is Interface Polymorphism?with E.g



What is Interface Polymorphism?with E.g..

Answer / 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

More C Sharp Interview Questions

Is datetime value type c#?

0 Answers  


Does c# support const methods, properties, or events?

0 Answers  


hi all.... i need code snippets for store and retrive tiff fromat images in sqlserver....... kindy provide it.......

0 Answers   Tricom,


How do you create dlls in .NET

0 Answers   Digital GlobalSoft,


Are arrays immutable c#?

0 Answers  






What's the difference between System.String and System..StringBuilder in C#?

0 Answers   PUCIT,


can we declare a variable by name "this" in a class? Please explain?

3 Answers   IBM,


Is int reference type c#?

0 Answers  


What is exe in c#?

0 Answers  


What is the use of table aliases?

0 Answers  


How is method overriding different from overloading?

0 Answers  


What are circular references?

0 Answers  


Categories