Solution (source code)

= Solution

A graphical-component library can provide `protected void paintComponent(Graphics g)` as a subclass customization hook, as in `javax.swing.JComponent`. A subclass overrides it to draw its own contents while the library retains responsibility for the surrounding painting protocol. A <protected method in Java> is accessible to code in the declaring package and to subclasses in other packages subject to the receiver restriction; it is not simply a public method and not exclusively subclass-visible.

\b[The benefit is controlled extensibility without exposing an ordinary client operation.] If the method were private, external subclasses could not override and reuse it as the intended hook. If it were public, arbitrary clients could call it outside the normal painting lifecycle and the library would have a wider public contract to maintain. Protected hooks still require documented invariants because subclass code participates in the implementation.