It will call the child method if it overrides the parent method. But this is not so, since the parent method is private and therefore cannot be overridden.
When you intend to override a method from the parent class or interface, you should always annotate the method with @Override . If you did this, in this case you would get an error from the compiler, since child method1 does not override any method.
When the parent class is compiled, the compiler searches for method1 in the parent class. He finds it and sees that he is private. Since it is confidential, it knows that it is not overridden by any subclass, and thus statically links the method call to the private method it finds.
If method1 was protected or publicly accessible, the compiler will find this method and will know that this method can be overridden by a subclass. Therefore, it will not be statically bound to the method. Instead, it generates a bytecode that method1 will look for in a particular class at runtime, and then you get the expected behavior.
Think about it: if a subclass can override a private method, this method will no longer be closed.
Jb nizet
source share