Difference Between Class and Interface in Java


In this post, we will understand the difference between class and an interface in Java.

Class

  • It tells about the attributes and behaviours that an object needs to possess.

  • It can contain abstract methods as well as normal methods.

  • Keyword to create it is ‘class’.

  • It can be instantiated.

  • It doesn’t support multiple inheritance.

  • It can inherit a class.

  • The name of the class’s parent (if any) is preceded by the keyword ‘extends’.

  • The members in a class can be public, private or protected.

  • The class body is surrounded by ‘{‘ and ‘}’.

  • Variables could be static or final or normal variables.

Interface

  • It contains behaviours that are implemented by a class.

  • Keyword to create it is ‘interface’.

  • It can’t be instantiated.

  • It supports multiple inheritance.

  • It can contain abstract methods only.

  • It uses’ extends’ to inherit an interface.

  • All variables are static and final.

  • It can’t inherit a class.

  • It is a blueprint for the class.

  • It tells what a class must do, not how it should achieve it.

  • The members of an interface are public by default.

Updated on: 24-Mar-2021

452 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements