Difference between Abstract and Interface | Abstract vs Interface

: 113
Paper : Java FAQ (Frequently Asked Questions and answers) for freshers | Platform : Object-oriented programming Language | Category : Programming FAQs

For achieving abstraction both abstract and the interface is used. The abstract class helps in partial abstraction and interface achieves full abstraction. Let us study the difference between the two in the table given below.

Abstract class

Interface

A class that is abstract can have both abstract and non-abstract methods.

The interface on the other hand can have only abstract methods. However, after Java 8, it can have default and static methods also.

It does not support multiple inheritances.

It supports multiple inheritances.

Abstract class contains final, non-final, static and non-static variables.

The interface can contain only static and final variables.

An abstract class can provide an implementation of the interface.

It cannot implement the abstract class.

If we want to declare a class as abstract we need to use the abstract keyword.

To declare interface we use the interface keyword.

It can extend another Java class and multiple java interfaces can be implemented.

It can only extend another Java interface.

The “extends” keyword is used to extend an abstract class.

“implements “keyword is used.

Class members can be private, protected etc.

Class members are by default public.

Example

Public abstract class painting{

Public abstract void draw();}

Example

Public interface Creation{

Void draw();}