title: Java: use getters and setters with polymorphism
body: <p>I have for example these classes:</p>
  
  <pre><code>public class A {
  }
  
  public class B {
  }
  
  public class Parent {
      private A a;
      public A getA() {
          return a;
      }
      public void setA(A a) {
          this.a = a;
      }
  }
  
  public class Child extends Parent {
      private B b;
      public B getB() {
          return b;
      }
      public void setB(B b) {
          this.b = b;
      }
  }
  </code></pre>
  
  <p>And in my Main class I would like to use polymorphism: <code>Parent p = new Child();</code>.
  I need to use setA and setB functions both on this p element. What is the best way to do this? I see right now just the setA function because of the polymorphism - so do I have to override the setters and getters in the child class? Is it recommended? </p>