title: Android create object of one of the similar classes
body: <p>I have two classes that do the same things but by the different ways. I need to create an object of one of these classes depending on config settings. Here is a brief example of what do I want to do. </p>
  
  <pre><code>public class A {
      public string getLetter() {
          return "A";
      }
  }
  public class B {
      public string getLetter() {
          return "B";
      }
  }
  
  public class MainActivity {
      private myObject; // How to declare it in my case?
      private int config = 0;
  
      public void onCreate(Bundle savedInstanceState) {
          if (config == 0) {
              myObject = new A();
          } else {
              myObject = new B();
          }
          String letter = myObject.getLetter();
      }
  }
  </code></pre>
  
  <p>Actually everything is much more complex. Each of classes A and B asynchronously listens to the different sources of data, converts it to the format that can be used in further processing and passes it to MainActivity. Depending on configuration only one source of data must be selected. How can I do this? Variant with </p>
  
  <pre><code>letter = A.getLetter(); 
  </code></pre>
  
  <p>will not work.</p>