Listing 3 is ambiguous because both superclasses define method m1.
Listing 3: | ambiguousmethod |
However, in this case, we have to ways to resolve the ambiguity. First, we can change line 22 to the following:
myC.A::m1();
|
However, we can also choose a “default” method m1 in the definition of class C. We can change the definition of class C as follows:
This tells the compiler that when we refer to method m1 of a class C object, by default we refer to that of class A.
Note that with this default, we can still change the statement on line 22 to specify the method m1 or class B using the syntax myC.B::m1().