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 difference between throw and throws in c#?

0 Answers  


What is default value of bool in c#?

0 Answers  


What does it meant to say “the canonical” form of XML ?

1 Answers  


What is difference between array and list in c#?

0 Answers  


Major difference between Basic httpbinding and WShttpbinding?

0 Answers   QuestPond,






I have to create a windows application using C# .net to Modifiy the XML file. The application have to show the node and node value. plz help me.

3 Answers   Merrill Lynch,


When do you generally use a class over a struct?

0 Answers  


What is the real use of interface in c#?

0 Answers  


What is constructor overloading in c#?

0 Answers  


What is wpf c#?

0 Answers  


Describe two uses of the “using” statement during the operation of c#?

0 Answers  


Is c# a keyword?

0 Answers  


Categories