title: Call a child class method from a parent class object
body: <p>I have the following classes</p>
  
  <pre><code>class Person {
      private String name;
      void getName(){...}}
  
  class Student extends Person{
      String class;
      void getClass(){...}
  }
  
  class Teacher extends Person{
      String experience;
      void getExperience(){...}
  }
  </code></pre>
  
  <p>This is just a simplified version of my actual schema. Initially I don't know the type of person that needs to be created, so the function that handles the creation of these objects takes the general <code>Person</code> object as a parameter. </p>
  
  <pre><code>void calculate(Person p){...}
  </code></pre>
  
  <p>Now I want to access the methods of the child classes using this parent class object. I also need to access parent class methods from time to time so <strong>I CANNOT MAKE IT ABSTRACT</strong>. </p>
  
  <hr>
  
  <p>I guess I simplified too much in the above example, so here goes , this is the actual structure. </p>
  
  <pre><code>class Question {
    // private attributes
    :
    private QuestionOption option;
    // getters and setters for private attributes
    :
    public QuestionOption getOption(){...}
   }
  
   class QuestionOption{
   ....
   }
   class ChoiceQuestionOption extends QuestionOption{
   private boolean allowMultiple;
   public boolean getMultiple(){...}
   }
  
   class Survey{
    void renderSurvey(Question q) {
        /*
            Depending on the type of question (choice, dropdwn or other, I have to render
            the question on the UI. The class that calls this doesnt have compile time 
            knowledge of the type of question that is going to be rendered. Each question 
            type has its own rendering function. If this is for choice , I need to access 
            its functions using q. 
        */
        if(q.getOption().getMultiple())
          {...}
    }
   }
  </code></pre>
  
  <p>The if statement says "cannot find getMultiple for QuestionOption." OuestionOption has many more child classes that have different types of methods that are not common among the children (getMultiple is not common among the children)</p>