As the others suggested, the default
keyword has two main uses:
- Prior to Java 8, it can only be employed to trigger the default case in a
switch-case
statement.
- From Java 8 onwards, developers are allowed to provide implemented methods inside interfaces (which previously wasn't possible), with the use of the
default
keyword at the method's declaration (public default int method()
).
As far as I understand, using the default
keyword at a method's declaration when in a simple class, does not make any difference at all.
For an extensive discussion on the purpose of default
methods in interfaces, see Purpose of Default or Defender methods in Java 8