What is the difference between an abstract class and an interface in Java?

PointAbstract classInterface
InheritanceA class extends only oneA class implements many
FieldsAny kind of fieldsOnly constants (public static final)
ConstructorsYesNo
MethodsAbstract and normalAbstract, default, static and private
Use whenRelated classes share code and stateDifferent classes share a behavior

A good rule: use an interface to say what something can do, and an abstract class to share code between closely related classes. See Abstract Classes and Interfaces.


Learn more about the similar topics:
Tutorials
No Content Found.
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.