Java Reference
In-Depth Information
public
public default
void
welcome
() {
message
(
"Child: Hi!"
);
default
void
}
}
You can see the class hierarchy at this point in
Figure 4-4
.
Figure 4-4. A diagram showing the inheritance hierarchy at this point
Example 4-14
calls this interface and consequently ends up sending the string
"Child:
Hi!"
.
Example 4-14. Client code that calls our Child interface
@Test
public
public
void
void
childOverrideDefault
() {
Child child
=
new
new
ChildImpl
();
child
.
welcome
();
assertEquals
(
"Child: Hi!"
,
child
.
getLastMessage
());
}
Now the
default
method is a virtual method—that is, the opposite of a static method. What
this means is that whenever it comes up against competition from a class method, the logic
for determining which override to pick always chooses the class. A simple example of this is
chosen over that of
Parent
.