3
Reply

Interfaces - Why we need them?

sarav

sarav

Aug 3 2004 8:55 AM
2.5k
why do we need interfaces ... Suppose we have two interfaces like interface I1 { void display(); } interface I2 { void show(); } Suppose we implement these interfaces in a class as shown ... class ImplementInterfaces : I1, I2 { public void display() { Console.WriteLine("Display method in I1"); } public void show() { Console.WriteLine("show method in I2"); } } Suppose we have our program in a class like this ... class interfaceDemo { static void Main() { ImplementInterfaces obj = new ImplementInterfaces(); obj.display(); obj.show(); } } ---------------------------------------------------------------------------------------- my question is, if we are going to declare and define what the methods are going to do in our class only then why take the pain of declaring them in an interface? Why do we need an interface if we are going to declare and define our methods explicitly in our class? We might as well get rid of both the interfaces and declare and define the show() and display() method in the class itself. why we need interfaces in the first place. eagerly awaiting a reply for this. regards, Sarav

Answers (3)