Skip to content

Instantly share code, notes, and snippets.

@verhas
Created August 8, 2025 13:37
Show Gist options
  • Save verhas/ffbb785deb80befe105a783653e8ab86 to your computer and use it in GitHub Desktop.
Save verhas/ffbb785deb80befe105a783653e8ab86 to your computer and use it in GitHub Desktop.
a simple private access demo
public class OverridePrivate {
private static class A {
private void foo() {
System.out.println("foo");
}
private void bar() {
System.out.println("bar");
}
}
private static class B extends A {
private void foo() {
System.out.print("B ");
super.foo();
}
}
public static void main(String[] args) {
A a = new A();
B b = new B();
a.foo();
a.bar();
b.foo();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment