java access modifiers with method overriding
Yes, an overridden method can have a different access modifier but it cannot lower the access scope.
The following rules for inherited methods are enforced -
- Methods declared public in a superclass also must be public in all subclasses.
- Methods declared protected in a superclass must either be protected or public in subclasses; they cannot be private.
- Methods declared private are not inherited at all, so there is no rule for them.
Published on 05-Feb-2018 12:15:38