Abstract class vs Interface Java

Abstract class vs Interface Java


After knowing what is an abstract class and interface in Java, let us summarize their differences. The differences Abstract class vs Interface given in a table format, at a single place, gives more clarity for a novice, attempting to learn Java.
Table on Abstract class vs Interface
Abstract class Interface
Supports multilevel and hierarchical inheritance but "not multiple inheritance" (main difference) Supports all types of inheritances – multilevel, hierarchical and multiple.
Can contain concrete methods also apart abstract methods(important difference) Must contain only abstract methods
Use "extends" keyword to inherit "implements" keyword should be used
Access specifier of an abstract method can be any one except private Access specifier must be public only
Access specifier like public and access modifier abstract should be mentioned All the methods must be public and abstract and if omitted, taken by default
When few methods are to be given functionality, choose abstract class When all the methods should not be given functionality, choose interfaces
Variables may be of any access specifier including private Variables must be public, static and final; and if omitted, taken by default
One abstract class cannot extend more than one abstract class One interface can extend more than one interface
Can have constructors Can not have constructors

Common functionalities (or similarities)
1. With the both, we cannot create objects but reference variables can be created.
2. Both support dynamic polymorphism.

Class vs Interface is also available.

Leave a Reply

Your email address will not be published. Required fields are marked *