Skip to content

Instantly share code, notes, and snippets.

@elizarov
Created January 30, 2019 14:50
Show Gist options
  • Save elizarov/712991cc0018fa0d2a7bc4398c5fbe0e to your computer and use it in GitHub Desktop.
Save elizarov/712991cc0018fa0d2a7bc4398c5fbe0e to your computer and use it in GitHub Desktop.
Package-private inheritance
package a;
public abstract class A {
abstract void foo();
public void callFooA() {
foo();
}
}
package b;
import a.A;
public abstract class B extends A {
void foo() {
System.out.println("B.foo()");
}
public void callFooB() {
foo();
}
}
package a;
import b.B;
public class C extends B {
void foo() {
System.out.println("C.foo()");
}
public static void main(String[] args) {
C c = new C();
c.foo();
c.callFooA();
c.callFooB();
}
}
/* Produces
C.foo()
C.foo()
B.foo()
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment