+ 2
What is an interface in java?
4 Respuestas
+ 5
An interface is similar to an abstract class, in that it has members that will be overriden by classes that implement the interface.
Or, better defined by oracle:
"In its most common form, an interface is a group of related methods with empty bodies".
Only the members/methods MUST be overriden if they're abstract. All members of the interface are abstract unless (Since java 8) explicitly defined not to be with the 'default' keyword.
Hopefully that made sense 👌
+ 2
interface allows you
to get objects to have
attributes of more than
one object
+ 2
the implements keyword is used when deriving from an interface
+ 1
Well I have seen a lot of theory definitions. Some better some worse. I preffer some particular usages of interface to determine its usage. Let's think about your app that stores data to some database. An other app wants to take data from Your app and work with them. To do so, You should not share your source code, instead You can make an interface with certain methods that allows host app to get acces to Your data. Other app can easilly cooperate with Your app through interface.