It's all about the visibility of variables / methods.
You will notice that in the Bar
class the testPrivate()
method is private
. This means that ONLY can access this method itself. No children.
Therefore, when Foo
extends Bar
, and then asks you to run the test()
method, it performs two functions:
- It overrides the
testPublic()
method because it is public, and Foo
has the right to override it with its own version. - It calls
test()
on Bar
(since test()
exists only in Bar()
).
testPrivate()
not overridden and is part of the class containing test()
. Therefore Bar::testPrivate
.
testPublic()
is redefined and is part of the inheritance class. Therefore, Foo::testPublic
.
source share