This code is from one of Dan Chisolm's single topic practice exams:
interface I {String s1 = "I";}
class A implements I {String s1 = "A";}
class B extends A {String s1 = "B";}
class C extends B {
String s1 = "C";
void printIt() {
System.out.print(((A)this).s1 + ((B)this).s1 +
((C)this).s1 + ((I)this).s1);
}
public static void main (String[] args) {
new C().printIt();
}
}
The correct output is given as ABCI, and that's what I get when I run it -- but I had thought it wouldn't even compile because the interface variable s1 is implicitly final and shouldn't be able to be reassigned. What am I missing here?
Thanks,
Kathy