Skip to content

Instantly share code, notes, and snippets.

@swankjesse
Created February 9, 2013 00:45
Show Gist options
  • Save swankjesse/4743248 to your computer and use it in GitHub Desktop.
Save swankjesse/4743248 to your computer and use it in GitHub Desktop.
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();
}
}
@swankjesse
Copy link
Author

On the desktop, overrides can cut through packages. Here's what the JVM prints:

    C.foo
    B.foo
    C.foo

@swankjesse
Copy link
Author

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