Interface and abstract class in Java
Interface in Java
Java does not support the multiple inheritance so, to overcome with this java gives concept of interface. Interface is a template that has only declaration of methods. It means when a class implement the interface then method implementation is done in that class.
For example, consider the following code-
Public abstract interface Calculation //interface declaration
{
public abstract void addition(); //method declaration
public abstract void division();
}
Note-Internally all the methods of interface are public abstract void and variables are public static final.
Abstract Class in Java
Abstract classes cannot create objects. So to access the methods of abstract class you need to inherited by that abstract class. Abstracted classes have both abstract as well as non-abstract methods. To create a abstract class you need to use ‘abstract’ keyword on before the class keyword.
For example, consider the following code-
public abstract class Calculation{
public abstract void addition(); //abstract method declaration
public void multiply(){}
}
Must Read – JIT Compiler