Abstract class vs Interface
by, 01-08-2012 at 12:15 PM (1018 Views)
Base classes are used to present interface to its child classes in design. It supports that base class cannot be instantiated. It can be only up casted and its interface is used only. To achieve this, mark the base class as abstract. Compiler gives an error, if you try to create an object of abstract class.
The interface helps and improves the concept of abstract class. In interfaces, you can only declare methods and cannot provide implementation. The child class which is implementing the interface should provide the functionality. It provides a separate layer between implementation and interfaces and helps you to:
• Integrate unrelated classes without a class relationship.
• Declare methods which will be used by different classes.
• Provide an interface to outer world without revealing its implementation details.
• Support multiple interface inheritance in Java.
In a situation where implantation inheritance is required, use abstract class. For polymorphism, low coupling and code reusability prefer to use interfaces.