September 16, 2008 at 6:34 PM
Interfaces are useful when you do not want classes to inherit from unrelated classes just to get the required functionality. For example, let bird be a class with a method fly(). It will be ridiculous for an aeroplane to inherit from bird class just because it has the fly() method. Rather the fly() method should be defined as an interface and both bird and aeroplane should implement that interface.
An interface is a contract between a class and the outside world. When a class implements an interface, it promises to provide the behavior published by that interface.
Consider different brant computer and analyze you got good scenario about Interface
September 16, 2008 at 6:49 PM
Uses of interface some points to be remember:
1. All variables in an Interface are by default - public static final while an abstract class can have instance variables.
2. An interface is also used in situations when a class needs to extend an other class apart from the abstract class.
In such situations its not possible to have multiple inheritance of classes.
An interface on the other hand can be used when it is required to implement one or more interfaces.
Abstract class does not support Multiple Inheritance whereas an Interface supports multiple Inheritance.
3.Interfaces are often used to describe the peripheral abilities of a class, and not its central identity,
E.g. an Automobile class might implement the Recyclable interface, which could apply to many otherwise totally unrelated objects.
4.Interfaces are useful in a situation when all its properties need to be implemented by subclasses.