Let’s discuss the differences and also the similarities between an Abstract Class and an Interface in terms of the Java programming language.
Abstract class will contain one or more abstract methods, which must be implemented by sub classes. Abstract class starts with the keyword abstract followed by the class definition. Abstract classes can contain one to many abstract methods.
Interface is a object that contains the method declaration but not the implementation. Any class that implements the Interfaces must provide the definition for all the methods. Interface must start with the keyword interface. Interfaces must contain all abstract methods and declarations.
- Abstract Class : Both Abstract & Non-Abstract Methods
- Interface : Only Abstract Methods
- Abstract Class : Static, Non-Static, Final, Non-Final
- Interface : Static, Final
- Abstract Class : Implementation of Interface
- Interface : Can’t Provide Implementation of Abstract Class
- Abstract Class : Extended Using Keyword extends
- Interface : Implement Using Keyword implements
- Abstract Class : Can be public, protected, private
- Interface : Default to Public
Abstract Class Sample Code
abstract class jcdAbstractClass
protected String jcdString;
public String getString()
Interface Sample Code
public interface jcdInterface
public void jcdDoSomething();
public int jcdInteger = 100;
It’s important to remember that you can’t instantiate an abstract class or an interface in Java.