by Dinesh Thakur Category: Classes

Interfaces and abstract classes both implements polymorphic behaviour and seem to be similar but they are different in the following ways:
1. An interface is purely abstract i.e. methods in an interface only have declarations no implementations. On the other hand, abstract class methods may or may not have an implementation.


2. A class implementing an interface must implement all of the methods declared in the interface while a class extending an abstract class need not implement any of the methods defined in the abstract class.
3. Abstract classes are used only when there is a IS-A relationship between the classes. However, interfaces can be implemented by unrelated classes.
4. You can implement more that one interface but you cannot extend more than one abstract class,
5. User-defined exception can be defined within an interface itself which is not the case with the abstract class.
6. Members of an abstract class may have any access specifier modifier but members of an interface are public by default and cannot have any other access specifier.
7. Abstract class definition begins with the keyword abstract followed by class definition. On the other hand, interface definition begins with a keyword interface.
8. All variables in an interface are public, static and final by default whereas an abstract class can have instance variables.
9. Abstract class does not support multiple inheritance whereas interface support multiple inheritance.
10. If you define an interface and then later add a new method to an interface then you must implement that method in all of the classes which implement that interface. However, in the case of an abstract class, you can safely add non-abstract methods to that class without requiring any modification to existing classes that extend the abstract class.
11. Interface are slow as compared to abstract class as they find the actual method in the corresponding classes.
12. Interface can extend another interface, whereas abstract class can extend another class and implement multiple interfaces.
13. An abstract class can have constructors but interface cannot have constructor.
14. Members of a Java interface are public by default. A Java abstract class can have the usual flavors of class members like private, protected, etc..
15. Java interface should be implemented using keyword “implements”; A Java abstract class should be extended using keyword “extends”.
16. An interface can extend another Java interface only, an abstract class can extend another Java class and implement multiple Java interfaces.
17. A Java class can implement multiple interfaces but it can extend only one abstract class.
18. Interface is absolutely abstract and cannot be instantiated; A Java abstract class also cannot be instantiated, but can be invoked if a main() exists.
19. In comparison with java abstract classes, java interfaces are slow as it requires extra indirection.



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Related Articles