I know I can use reflection to invoke a private method, and to get or set the value of a private variable, but I want to override a method.
public class Supe
No, you can't. You can construct a program which look like it should be able to do this, using the fact that code within an outer class can access nested class's private members. However, private methods still can't actually be overridden. Example:
public class Test {
public static class Superclass {
private void foo() {
System.out.println("Superclass.foo");
}
}
public static class Subclass extends Superclass {
private void foo() {
System.out.println("Subclass.foo");
// Looks like it shouldn't work, but does...
super.foo();
}
}
public static void main(String[] args) throws Exception {
Superclass x = new Subclass();
// Only calls Superclass.foo...
x.foo();
}
}
Given that this would be the only situation in which it was feasible to override a private method, it's no great loss that it's not supported.
If you want to change the behaviour of a private member of your superclass, your design is broken, basically.