Java Reference
In-Depth Information
The following code creates an instance of
MyIFImp
and uses it to call both
getUserID(
)
and
getAdminID( )
.
The output is shown here:
As you can see, the default implementation of
getAdminID( )
was automatically used.
It was not necessary for
MyIFImp
to define it. Thus, for
getAdminID( )
, implementation
by a class is optional. (Of course, its implementation by a class will be
required
if the class
needs to return a different ID.)
It is both possible and common for an implementing class to define its own implement-
ation of a default method. For example,
MyIFImp2
overrides
getAdminID( )
, as shown
here: