When overriding a method, why can I increase access but not decrease it?

yesilupper picture yesilupper · Jul 27, 2011 · Viewed 49.5k times · Source

Why does Java specify that the access specifier for an overriding method can allow more, but not less, access than the overridden method? For example, a protected instance method in the superclass can be made public, but not private, in the subclass.

Answer

Patrick87 picture Patrick87 · Jul 27, 2011

It's a fundamental principle in OOP: the child class is a fully-fledged instance of the parent class, and must therefore present at least the same interface as the parent class. Making protected/public things less visible would violate this idea; you could make child classes unusable as instances of the parent class.