public class F { public static class A { int methodA() { return 7; } } public static interface I { int methodI(); } private static class B extends A implements I { public int methodI() { return 12; } } private static class C extends A implements I { public int methodI() { return 17; } } public static T newThing() { return (T) new B(); } public static void main(String... _) { A $a = F.newThing(); I $i = F.newThing(); System.out.println($a.methodA()); System.out.println($i.methodI()); } }