concept MyInterface in category java

This is an excerpt from Manning's book OCA Java SE 8 Programmer I Certification Guide.
Certification aspirants frequently ask questions about static classes and interfaces, so I’ll quickly cover these in this section to ward off any confusion related to them. But note that static classes and interfaces are types of nested classes and interfaces that aren’t covered by the OCA Java 8 Programmer I exam.
Extending multiple interfaces with the same abstract method names
An abstract method doesn’t define a body. Consider the following code, whose UML representation is shown in figure 6.13. Which of the getName methods will be inherited by the interface MyInterface? Will MyInterface inherit the getName method defined in BaseInterface1 or the one defined in BaseInterface2?
Figure 6.13. The interface MyInterface extends the interfaces BaseInterface1 and BaseInterface2.
![]()
interface BaseInterface1 { String getName(); } interface BaseInterface2 { String getName(); } interface MyInterface extends BaseInterface1, BaseInterface2 {}Because neither of the getName methods defined in BaseInterface1 and Base-Interface2 define a method body (as shown in figure 6.14), the question of which of the methods MyInterface inherits is irrelevant. The interface MyInterface has access to a single getName method, which must be implemented by all the concrete classes that implement MyInterface.
Figure 6.14. Methods defined in an interface don’t have a method body.
![]()
Let’s make the Employee class implement the interface MyInterface, as follows:
When an interface extends multiple interfaces, Java ensures that it shouldn’t inherit multiple method implementations for the same method. In the following example, interface MyInterface won’t compile because it inherits unrelated defaults for getName() from types BaseInterface1 and BaseInterface2:
![]()
If you override the default implementation of the method getName() in MyInterface, it will compile successfully:
![]()
In the preceding code, the getName method in MyInterface can refer to a superinterface method by using the super keyword: