title: How to set fields in an abstract class?
body: <p>I have an abstract class with a field in it, which should have following properties:</p>
  <ul>
  <li>readonly for the public interface</li>
  <li>writeonly for the subclasses</li>
  </ul>
  <p>My question now is: how should I set and initialize this field?</p>
  <pre><code>public abstract class A {
      // initialize it here ?
      private int field = 0;
  
      // initialize it in constructor ?
      protected A(int field)
      {
          this.field = field;
      }
        
      // use protected setter ?
      protected void setField(int val){
          this.field = val;
      }
  
      // or use protected field
      protected int field;
  
      public int getField(){
          return field;
      }
  }
  </code></pre>
  <p>How to initialize/access this field?</p>
  <pre><code>public class B extends A {
      
      public B(int val){
          super(val);
          // or
          setField(val);
          // or
          field = val;
      }
  }
  </code></pre>
  <p>and is it a good idea to use something like a protected constructor?</p>