Microsoft Interview Question
Software Engineer in TestsUsing an interface is necessary when you want that the classes must implement some of the prerequired methods.
Ex. Employee inherits person class so employee should have eat function which is defined in person class so instead of making abstract class we make an interface person so that whenever any class in inheriting the class it will sign the contract to define eat person.
And ofcouse it supports multiple inheritance in java using interfaces.
And you can also support run time polymorphism using interfaces because the person interface derives manager and employee class so the reference of person can store the instance of manager as well as the instance of employee.
So using interface has many advantages.
To implement multiple inheritance like behaviour in C# .
- Anand July 31, 2009