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 a bool in c#?

0 Answers  


Can you allow class to be inherited, but prevent the method from being over-ridden?

5 Answers  


What are partial types in c#?

0 Answers  


What is string concatenation?

0 Answers  


Can main method be final?

0 Answers  






Can enum be null c#?

0 Answers  


Can delegates be used as callbacks?

0 Answers  


What is autopostback in c#?

0 Answers  


What is static classes?

0 Answers  


What is virtual class in C#?

0 Answers   B-Ways TecnoSoft,


Can we inherit private members of class in c#?

0 Answers  


Hai I am Shiva from TN, SSE.I have an query problem. My Table : Door Field : ID,DoorID,ZoneID,Date,Time,Status. Problem was : Status.We got two values, one is 00 (OUTTIME) , Another is 01(INTIME) Like this Status --------- 00 01 00 01 00 01 00 01 How to Set as Status 00 and 01 , of separate column , Status as Intime,Status as Outtime Like this ----------- InTime OutTime ---------- ----------- 01 00 01 00 01 00 01 00 01 00 01 00 Regards KS kumar

1 Answers  


Categories