Java Reference
In-Depth Information
public class C implements B, A {
public static void main(String... args) {
System.out.println(new C().getNumber());
}
}
What will the program print?
Answer:
C can't distinguish which method of A or B is more specific. This is why class C won't compile.
9.4.4. Diamond problem
Let's consider a final scenario that sends shivers through the C++ community:
Figure 9.8 illustrates the UML diagram for this scenario. It's called a diamond problem because
the shape of the diagram resembles a diamond. So what default method declaration does D
inherit—the one from B or the one from C? There's actually only one method declaration to
choose from. Only A declares a default method. Because the interface is a superinterface of D,
the code will print “Hello from A.”
Search WWH ::




Custom Search