I came across a question while taking iKM test. There was a base class with two abstract methods with private access specifier. There was a derived class which was overriding these abstract methods but with protected/public access specifier.
I never came across such thing where overridden methods in derived class had different access specification. Is this allowed ? If yes, does it comply to "IS A" relation between base and derived (i.e. safely substitutable).
Could you point me to some references which can provide more details on such usages of classes ?
Thank you.
It is allowed, in both directions (ie, from private
to public
AND from public
to private
).
On the other hand, I would argue it does not break the IS-A relationship. I base my argument on 2 facts:
Base&
(or Base*
) handle, you have exactly the same interface as beforepublic
and calling the private
method directly anyway: same effect with more typingIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With