+ 2

What is an interface in java?

7th Jun 2017, 7:31 PM
Chaman Raghav
Chaman Raghav - avatar
4 Réponses
+ 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 👌
7th Jun 2017, 8:08 PM
Rrestoring faith
Rrestoring faith - avatar
+ 2
interface allows you to get objects to have attributes of more than one object
7th Jun 2017, 8:10 PM
Abdur-Rahmaan Janhangeer
Abdur-Rahmaan Janhangeer - avatar
+ 2
the implements keyword is used when deriving from an interface
7th Jun 2017, 8:10 PM
Abdur-Rahmaan Janhangeer
Abdur-Rahmaan Janhangeer - avatar
+ 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.
7th Jun 2017, 8:50 PM
zdena