Would you use
System.out.println( super .getName());
You have an anonymous inner Solution class inside a Solution , so getName() implicitly referencing an external instance because the method is private.
You can also make getName secure rather than private.
The explanation is the ornery bit. getName displayed by an anonymous class due to scope, but since it is private, an anonymous class usually cannot reference getName on its own because it is actually a subclass.
In fact, the strange case is that you have a static nested subclass:
class Example { private void sayHello() { System.out.println(); } static class Subclass extends Example { Subclass() {
I looked at the spec in my answer to the static case, which also explains why "main" is printed here: fooobar.com/questions/176752 / ....
source share