View RSS Feed

Java Basic

Abstract class vs Interface

Rate this Entry
by , 01-08-2012 at 11:15 AM (1170 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.

Submit "Abstract class vs Interface" to Facebook Submit "Abstract class vs Interface" to Digg Submit "Abstract class vs Interface" to del.icio.us Submit "Abstract class vs Interface" to StumbleUpon Submit "Abstract class vs Interface" to Google

Categories
Interface

Comments