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 use of properties window?

0 Answers  


What do you mean by delegates and explain different types of delegates?

0 Answers  


What is yield return in c#?

0 Answers  


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

0 Answers  


What is a base class in C#?

0 Answers   TryTechnicals Pvt Ltd,






What is Partial class? What purpose we use it?

6 Answers   ACS, TATA,


What's the implicit name of the parameter that gets passed into the set method/property of a class?

0 Answers  


What is an indexer in c#?

0 Answers  


What is difference between list and dictionary in c#?

0 Answers  


Why is c# a good programming language?

0 Answers  


What are c# i/o classes?

0 Answers  


What?s the role of the DataReader class in ADO.NET connections?

2 Answers  


Categories