Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

For methods inside the interface why can’t you specify the accessibility modifier?

937


Explain data types in c#?

920


Can we set image Source dynamically using C# in WPF application?

1049


What are assemblies?

929


Which of the following API is used to hide a window?

1012


What is fcl in c#?

861


What is the use of oops in c#?

897


What the different phase/steps of acquiring a proxy object in webservice?

984


Define c# delegate?

987


What is difference between event and delegate in c#?

900


What is a web service in c#?

1116


Which one is trusted and which one is untrusted?

919


What is multithreading with .net?

979


How do you create user defined data types in c#?

996


What is the benefit of delegate in c#?

895