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

What is the difference between hashtable and dictionary in c#?

0 Answers  


What is Garbage Collection in .Net?

0 Answers  


How many bytes is a char c#?

0 Answers  


Is is possible to force garbage collector to run?

0 Answers  


Illustrate the process of code compilation in c#?

0 Answers  






Is array ienumerable c#?

0 Answers  


What is Implicit conversion in C#?

0 Answers  


So what makes your code really object-oriented #?

0 Answers  


What are the fundamental oop concepts?

0 Answers  


How do I open the console?

0 Answers  


what is the difference between the debug class and trace class?

0 Answers   Rolta,


What is difference between ienumerable and ienumerator in c#?

0 Answers  


Categories