Most efficient approach in inherited fields?
<p>Consider a certain class hierarchy consisting of a root class and some subclasses  </p>

<pre><code>    R
    |
 .--+--+------.
 |     |  ... |
S1     S2 ... Sn
</code></pre>

<p>Class R has a field <code>x</code> of a certain type, say <code>X</code>, which is not a simple type, that every subclass should inherit. Subclasses can do sorts of internal processing on field <code>x</code> as well as expose it as a property.
Sort of a discussion arose about which of these two coding style was preferrable:</p>

<h3>1st solution</h3>

<p>Have class <code>R</code> declare <code>x</code> as a private field and provide public getter and setter</p>

<pre><code>class R {
    ....
    private X x;

    ....

    public X getX() { ... }
    public void setX(X ax) { ... }
}
</code></pre>

<h3>2nd solution</h3>

<p>Have class <code>R</code> declare <code>x</code> as a protected field</p>

<p>Which one, in your opinion, could be the preferrable solution?</p>
