Default Methods

suggest change

Versions

[{“Name”:“Java SE 8”,“GroupName”:null},{“Name”:“Java SE 9 (Early Access)”,“GroupName”:null}]

Introduction

Default Method introduced in Java 8, allows developers to add new methods to an interface without breaking the existing implementations of this interface. It provides flexibility to allow the interface to define an implementation which will be used as default when a class which implements that interface fails to provide an implementation of that method.

Syntax

Remarks

Default methods

Static methods

Below is a table summarizing the interaction between sub-class and super-class.

-| SUPER_CLASS-INSTANCE-METHOD | SUPER_CLASS-STATIC-METHOD —— | —— | ——SUB_CLASS-INSTANCE-METHOD | overrides | generates-compiletime-error

SUB_CLASS-STATIC-METHOD | generates-compiletime-error | hides

Below is a table summarizing the interaction between interface and implementing-class.

-| INTERFACE-DEFAULT-METHOD | INTERFACE-STATIC-METHOD —— | —— | ——IMPL_CLASS-INSTANCE-METHOD | overrides | hides

IMPL_CLASS-STATIC-METHOD | generates-compiletime-error | hides

References :

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Default Methods:
* Default Methods

Table Of Contents
8 Arrays
10 Maps
11 Strings
13 Default Methods
25 JAXB
29 Enums
32 Audio
41 Scanner
63 Logging
75 Lists
78 Sets
89 JAX-WS
96 XJC
98 Process
106 Modules
114 Applets
122 JNDI
139 JavaBean
141 Literals
144 Packages
150 JMX
153 JShell
159 Sockets
167 Enum Map
175 Hashtable
177 SortedMap