With, interfaceyou can use some dexterity to hide methodFromA, but you cannot remove it.
class A {
public void methodFromA() {
System.out.println("methodFromA");
}
}
class B extends A {
public void methodFromB() {
System.out.println("methodFromB");
}
}
class C extends B {
}
interface D {
public void methodFromB();
}
class E extends B implements D {
}
public void test() {
C obj = new C();
obj.methodFromA();
D d = new E();
d.methodFromB();
d.methodFromA();
E e = (E) d;
e.methodFromA();
}
source
share