title: Java - Change reference variable
body: <p>So I know that reference variables cannot be changed.</p>
  
  <p>I'm in a position where I have two different classes. Let's call them A and B. They have the same methods (the methods are called the same) they're just specified for the class. </p>
  
  <p>I need a clever way of changing between which classes to instantiate.</p>
  
  <p>One way could be with some boolean tests checking which option has been selected and then instantiate the corresponding class. Although I fear that this might become bulky and ugly, so I'm trying to avoid this way. There must be something more clever.</p>
  
  <p>Currently I'm thinking of making a new class (e.g. C) that extends the same class as A and B.</p>
  
  <p>I would then override the methods (as class A and B also do btw) and then execute the methods depending on the setting (i.e. which class A or B is selected). The methods would return the same as it would in class A or B.</p>
  
  <p>Hope I'm not talking complete gibberish.</p>