When the compiler looks at println(m.i) it sees you've declared variable m as type myInter, so it looks at myInter to find variable i and finds the static final which happens to hold 5. The fact that variable m actually points to an object of type interface2 doesn't come into play because the compiler looks at the declared type.
You actually have a second variable i in the class myInter. You could print 7 by declaring m as myInter or by casting to myInter: println( (myInter)m.i );
This kind of confusion is a good reason to never "shadow" variables by creating new ones with the same name and different scope. As a
test question it's good just to make sure you know why it's such a bad programming practice.
BTW: Class and interface names start with capital letters by
Java convention ... Interface2 and MyInter would be better.
[ June 20, 2004: Message edited by: Stan James ]