title: Why am I getting this error "The constructor is undefined"?
body: <p>In Java, getting this error:</p>
  
  <pre><code>Error: The constructor MyComplex(MyComplex) is undefined
  </code></pre>
  
  <p>Java Code:</p>
  
  <pre><code>public class MyComplex {
      int realPart, imaginaryPart;
      public MyComplex(){
      }
      public MyComplex(int realPart, int imaginaryPart) {
          this.realPart = realPart;
          this.imaginaryPart = imaginaryPart;
      }
      public void setRealPart(int realPart) {
          this.realPart = realPart;
      }
      public String toString() {
          return realPart + " + " + imaginaryPart +"i";
     }
  }
  public class MyComplexTester {
      public static void main(String[] args) {
          MyComplex a = new MyComplex(20, 50);
          MyComplex b = new MyComplex(a);        //Error happens here
          b.setRealPart(4);
          System.out.println(b);
      }
  }
  </code></pre>
  
  <p>The code works fine if I use </p>
  
  <pre><code>MyComplex b = a;
  </code></pre>
  
  <p>But I can't change the code in the main method since its a homework on designing the class to run the given method.</p>