- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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.