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

What are the drawbacks of extending an interface as opposed to extending a class?

545


What is the use of oops in c#?

589


What is _viewstart cshtml?

554


What is indexer c#?

555


Give an example of removing an element from the queue?

557






Is it possible to force garbage collector to run?

552


What are the steps to create a webservice and consume it?

544


What are Regex / regular expressions ?

688


How many bytes is an int?

566


What is the difference between null and string empty in c#?

537


List the 5 different access modifiers in c#?

591


What is the difference between C# 3.5 and C# 4.0?

621


How to handle exceptions that are raised in a component?

683


What is jit? What are the different types of jit?

650


Is string a data type in c#?

558