Difference between Class and Interface in Java


In Java, class is a user-defined data type with a template that serves to define its properties. A class is essentially a description of how to make an object that contains fields and methods.

Interface in Java:

An Interface is a kind of class, it contains methods and variable. It defines only abstract methods and final fields.

Class vs Interface in Java:

1. The members of a class can be constant or variables.1. The members of an interface are always declared as constant and those values are final.
2. It can be instantiated by declaring objects. 2. It can't be used to declare objects. It can only be inherited by a class.
3. The methods in a class can be abstract or non-abstract.3. The methods in an Interface are only abstract.
4. It can use various access specifiers like public, private or protected.4. It can only use the public access specifier.