Unit_9: Java Interfaces Flashcards
What is Java interfaces?
An Interface in Java is a structure that lists (public)
methods that are to be required by classes that
implement the interface
Every method is public and abstract automatically in
an interface
There are no true data members (not in the sense of
inherited variables anyway – any data members we
declare are implicitly public, static, and final, i.e.
class-level constants)
There is no restriction on the number of Interfaces a
Class implements
What is powerful feature of interface?
An interface acts like a type, just as a class does!
=> So not only can we implement Measurable, we can
have variables of type Measurable! (or parameters,
return types, etc.)
What is default methods?
- Defined in an interface:
default int getSomething() { … } - A default method has code!
- If an interface extends another that has a default
method, it can redeclare (as abstract), override, or
leave implementation unchanged - An implementing class can keep the default
behaviour or change it