Interface (Java): Difference between revisions

Content deleted Content added
clarified the difference between an interface and an abstract class.
Tags: Reverted Mobile edit Mobile web edit
Line 5:
 
One benefit of using interfaces is that they simulate [[multiple inheritance]]. All classes in Java must have exactly one [[base class]], the only exception being {{Javadoc:SE|package=java.lang|java/lang|Object}} (the [[top type|root class]] of the Java [[type system]]); [[multiple inheritance]] of classes is not allowed. However, an interface may inherit multiple interfaces and a class may implement multiple interfaces.
 
There can be some confusion about the difference between an interface and an abstract class in Java. The technical difference is that an interface can only declare methods (which are implicitly abstract) and constants. On the other hand, an abstract class can have members, methods (abstract or not), and constructors<ref>Python Abstract Class vs Interface[https://ioflood.com/blog/java-abstract-class-vs-interface/]</ref>.
 
== Overview ==