Created
February 9, 2013 00:45
-
-
Save swankjesse/4743248 to your computer and use it in GitHub Desktop.
This file contains 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 p1; | |
public class A { | |
void foo() { | |
System.out.println("A.foo"); | |
} | |
public void aFoo() { | |
foo(); | |
} | |
} | |
// // // // // // // // // // | |
package p2; | |
import p1.A; | |
public class B extends A { | |
void foo() { | |
System.out.println("B.foo"); | |
} | |
public void bFoo() { | |
foo(); | |
} | |
} | |
// // // // // // // // // // | |
package p1; | |
import p2.B; | |
public class C extends B { | |
void foo() { | |
System.out.println("C.foo"); | |
} | |
public void cFoo() { | |
foo(); | |
} | |
} | |
// // // // // // // // // // | |
import p1.A; | |
import p2.B; | |
import p1.C; | |
public class Main { | |
public static void main(String[] args) { | |
C c = new C(); | |
c.aFoo(); | |
c.bFoo(); | |
c.cFoo(); | |
} | |
} |
On Dalvik, the package-private boundary is not respected. Here's what dalvikvm prints:
C.foo
C.foo
C.foo
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
On the desktop, overrides can cut through packages. Here's what the JVM prints: