title: How to return different types via a singleton instance method
body: <p>How can i return another class instance in my class contractor ?<br>
  my pseudo code is :  </p>
  
  <pre><code>class test
  {
      private test() {}
  
      public static test getInstance() 
      {
          if(Condition)
          {
              return new otherClass();
          }
          else
          {
              return new test();
          }
      }
  }
  </code></pre>