Created
January 30, 2019 14:50
-
-
Save elizarov/712991cc0018fa0d2a7bc4398c5fbe0e to your computer and use it in GitHub Desktop.
Package-private inheritance
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package a; | |
public abstract class A { | |
abstract void foo(); | |
public void callFooA() { | |
foo(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package b; | |
import a.A; | |
public abstract class B extends A { | |
void foo() { | |
System.out.println("B.foo()"); | |
} | |
public void callFooB() { | |
foo(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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