Difference Between Interface and Abstract Class

1) An Interface should contain only definitions but no implementation. where as an abstract class can contain abstract and non-abstract methods. 
2) Abstract class contains one or more abstract methods. where as Interface contains all abstract methods and final declarations
3) Abstract class contains the method defination of the some methods. but Interface contains only method declaration, no defination provided.
4) Interface must always have by default public and abstract methods.while abstract class can have non abstract methods
5) Abstract classes must be given by keyword abstract,where as in interface class with key word interface
6) By default what ever variables we declare in interface are public static final,where as in abstract class they can be default and instance variables also .
7) Abstract classes have constructors whereas interface do not have constructors.
8) Java interface should be implemented using keyword “implements”; A Java abstract class should be extended using keyword “extends”.
9) An interface can extend another Java interface only, an abstract class can extend another Java class and implement multiple Java interfaces.
10) In comparison with java abstract classes, java interfaces are slow as it requires extra indirection.
11) Abstract classes are used only when there is a “is-a” type of relationship between the classes. Whereas Interfaces can be implemented by classes that are not related to one another.
12) You cannot extend more than one abstract class. While You can implement more than one interface. 

People who read this post also read :



0 comments:

Post a Comment

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More