interface Data1 { int a = 1; int b = 2; int calc1(); int calc2(); } interface Data2 extends Data1 { int c = 3; int calc3(); } interface Data3 { int d = 4; int calc4(); } class DataA implements Data1 { public int calc1() { return a; } public int calc2() { return b; } } class DataB extends DataA implements Data2, Data3 { public int calc3() { return c; } public int calc4() { return d; } } public class InterfaceFun2 { public static void main(String[] args) { DataA x = new DataB(); // What happens if you use a ref type that doesn't specify // at least one method that the object uses? // At compile time, Java checks method names with static binding, // so the following won't work because calc3 and calc4 aren't in DataA: // System.out.println(x.calc1()+""+x.calc2()+""+ // x.calc3()+""+x.calc4()); // The following *does* work because the calc1 method is in DataA // and none of the other methods are inspected: System.out.println(x.calc1()); } } // output: 1