What exactly is the difference between an interface and abstract class?
The shortest way to sum it up is that an interface
is:
default
and static
methods; while it has definitions (method signatures + implementations) for default
and static
methods, it only has declarations (method signatures) for other methods.interface
s, and an interface
can inherit from multiple interface
s). All variables are implicitly constant, whether specified as public static final
or not. All members are implicitly public
, whether specified as such or not.Meanwhile, an abstract
class is:
abstract
methods. Can contain both declarations and definitions, with declarations marked as abstract
.protected
, private
, or private package (unspecified).Or, if we want to boil it all down to a single sentence: An interface
is what the implementing class has, but an abstract
class is what the subclass is.