As per the JLS 9.3:
If two fields with the same name are inherited by an interface because, for example, two of its direct superinterfaces declare fields with that name, then a single ambiguous member results. Any use of this ambiguous member will result in a compile-time error.
The field CONSTANT
in SubClassConstants
has hidden the CONSTANT
of SuperClassConstants
. But the class SubClass
has access to both the CONSTANT
as it virtually implements both the interfaces.
You can remove the ambiguity by specifying the Interface name :
System.out.println(SubClassConstants.CONSTANT);
Also read JLS 6.5.6.1:
If an expression name consists of a single Identifier, then there must be exactly one declaration denoting either a local variable, parameter, or field visible (§6.4.1) at the point at which the Identifier occurs. Otherwise, a compile-time error occurs.