Do I understand correctly that when redefining methods, modifiers ( private , public , static ) of a subclass must necessarily correspond to superclass modifiers? How do modifiers match when redefining methods?
1 answer
Sequence of modifiers in decreasing level of closeness: private, default ,protected, public .
During inheritance, it is possible to change access modifiers in the direction of greater visibility. Private methods are available only in the class in which they are described. In the class of the heir, you can declare the same method with the same signature but with another access modifier. So doing is considered bad practice. Protected methods can be extended to public.
|