Class vs Interface Java

Class vs Interface Java


We know Java supports three types of classes – Concrete, abstract and interfaces. After summarizing the difference between abstract classes and interfaces, let us tabulate the difference between classes and interfaces.

Class
Interface
Supports only multilevel and hierarchical inheritances but not multiple inheritance Supports all types of inheritance – multilevel, hierarchical and multiple
"extends" keyword should be used to inherit "implements" keyword should be used to inherit
Should contain only concrete methods (methods with body) Should contain only abstract methods (methods without body)
The methods can be of any access specifier (all the four types) The access specifier must be public only
Methods can be final and static Methods should not be final and static
Variables can be private Variables should be public only
Can have constructors Cannot have constructors
Can have main() method Cannot have main() method as main() is a concrete method

Know also the differences between abstract class vs interface.

One thought on “Class vs Interface Java

Leave a Reply

Your email address will not be published. Required fields are marked *