Class | Interface |
---|---|
The keyword used to create a class is "class". | The keyword used to create a interface is "interface". |
A class can be instantiated i.e, objects of a class can be created. | An Interface cannot be instantiated i.e, objects cannot be created. |
Classes does not support multiple inheritance. | Interface supports multiple inheritance. |
It can be inherit another class. | It cannot inherit a class. |
It can be inherited by another class using the keyword ‘extends’. | It can be inherited by a class by using the keyword ‘implements’ and it can be inherited by an interface using the keyword ‘extends’. |
It cannot contain abstract methods. | It contains abstract methods only. |
Variables in a class can be static, final or neither. | All variables are static and final. |
It can contain constructors. | It cannot contain constructors. |
Variables and methods in a class can be declared using any access specifier(public, private, default, protected) | All variables and methods in a interface are declared as public. |