Share on Google+Share on Google+

Interface Vs Abstract Class

There are three main differences between an interface and an abstract class:

Interface Vs Abstract Class


There are three main differences between an interface and an abstract class:
  • At the same time multiple interfaces can be implemented, but only extend one class
  • an abstract class may have some method implementation (non-abstract methods, constructors, instance initializers and instance variables) and non-public members
  • abstract classes may or may not be a little bit faster

Main reason for the existence of interfaces in Java is: to support multiple inheritance. Languages supporting multiple implementation inheritance, an interface is equivalent to a fully abstract class (a class with only public abstract members).

The above differentiation suggests when to use an abstract class and when to use an interface:

  • If you want to provide common implementation to subclasses then an abstract class is used,
  • If you want to declare non-public members, the use abstract method
  • In case of abstract class, you are free to add new public methods in the future,
  • If you're confirm regarding the stablity of the API for the long run then use an interface
  • If you want to provide the implementing classes the opportunity to inherit from other sources at the same time then use an interface.

In general, prefer interfaces if you don't need to use an abstract class, because they provide more design flexibility.


Posted on: March 18, 2005 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Discuss: Interface Vs Abstract Class   View All Comments

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
sai kumar
September 26, 2011
Replay for answer

this is very usefull to me thank you for your responce
komal karwa
July 23, 2012
interface and abstract class

it better but you don't give example from interface and abstract class and how will be used and what the works of interface and abstract class please it's some detail