Both the Java interface and abstract class contain abstract methods. An abstract method is nothing but a method without body and is terminated with a semicolon. Let us know the differences between an Interface and Abstract class in this Last Minute Java Tutorial.
Differences between Java Interface and Abstract Class
Check the below table that presents differences between abstract class and interface side by side.
|An abstract class contains both abstract and non-abstract methods.||All methods in an interface are abstract implicitly. It is 100% abstract.|
|The keyword used to create an abstract class is "abstract".||The keyword used to create an interface is "interface".|
|An abstract class can not be declared final.||An interface can not be declared final.|
|The keyword used to subclass an abstract class is "extends".||The keyword used to create a concrete class that implements abstract methods is "implements".|
|An abstract class can contain static variables and methods.||An interface contains only public static final variables. Static methods are supported from Java 8 version.|
|Static methods of an abstract class can be called directly using the class-name or instance variable.||Static method of an interface can be called directly using the Interface-name but not with an instance variable.|
|A concrete-class or an abstract-class can subclass only one abstract class.||A concrete-class or an abstract class can implement any number of interfaces.|
|You can not use the default method in an Abstract class.||You can use a default method only in interfaces.|
|An abstract class can implement an interface.||An interface can not extend an abstract class or concrete class.|
|An abstract class can become a subclass to another abstract class.||An interface can extend another interface.|
|You can not use the keyword "interface" in conjunction with the keyword "abstract".||You can use the keyword "abstract" with the keyword "interface. Even if you do not declare abstract, it is implicit.|
This is how we performed Java Interface Vs Abstract-Class comparison.
Share this Last Minute Java Interface and Abstract-Class comparison article with your friends and colleagues to encourage authors.
|2.||Java Interface with default method and static method|
|3.||Difference between Abstract Class and Interface|