question taken from Enthuware
Test 1
class TestClass implements I1, I2
{
public void m1() { System.out.println("Hello"); }
public static void main(
String[] args)
{
TestClass tc = new TestClass();
( (I1) tc).m1(); // line 1
}
}
interface I1
{
int VALUE = 1;
void m1();
}
interface I2
{
int VALUE = 2;
void m1();
}
the folowing question gives o/p as Hello. class TestClass implements both I1 and I2 and both
contain same methods, so how is the call to m1 on line 1, resolved be the JVM ???
i understand that if i say S.o.p( (I1) tc ).m1( ); after line 1, then it will call VALUE=1 of
interface I1. But the implementation of m1( ), does it belong to I1 or I2 ???
please explain
thanks in advance