posted 24 years ago
Hello,
Here is difference between Interfaces and Abstract Class
1. Interfaces can't have any method implementation, where as Abstrcat class can have method implementation.
2. Abstract class must be inherited, and give implementation for methods declared abstract, otherwise the derived class must be also declare Abstract, whereas Interfaces and implemented by class(implements iterface_name). If class implements any interface, it must give implementation for all method declared in Iterface.
3. A class can on extend from only one Abstrcat class(or concrete class), but a class can implement 2 or more Interfaces
4. Interfaces helps in adding types to class, this is not with abstract class.
5. Interface can be used to establish relation between unrelated class.
6. Interface helps in writing future safe code, it also facilites
writing generic code.
Though there is no method implemented in interface, it is very helpful. There is some thing called Tagging Interface which do not have any method, it just helps in marking the class for that interface. e.g. Serializable is tagging interface with no method.
Regards,
Sujit