0

I was making a class of functions to be performed on complex numbers. When I create a new object I get the following error:

error: constructor ComplexNumbers in class ComplexNumbers cannot be applied to given types; ComplexNumbers c1 = new ComplexNumbers(real1, imaginary1); ^ required: no arguments found: int,int reason: actual and formal argument lists differ in length

error: constructor ComplexNumbers in class ComplexNumbers cannot be applied to given types; ComplexNumbers c2 = new ComplexNumbers(real2, imaginary2); ^ required: no arguments found: int,int reason: actual and formal argument lists differ in length

2 errors

Code from main

    int real1 = s.nextInt();
    int imaginary1 = s.nextInt();

    int real2 = s.nextInt();
    int imaginary2 = s.nextInt();

    ComplexNumbers c1 = new ComplexNumbers(real1, imaginary1);
    ComplexNumbers c2 = new ComplexNumbers(real2, imaginary2);

Constructor code

public void ComplexNumbers(int real, int imaginary){
    this.real=real;
    this.imaginary=imaginary;
    return;
}
3
  • a constructor has no return type. the posted code should not pass compilation Commented May 13, 2019 at 7:23
  • public void ComplexNumbers is not a constrcutor Commented May 13, 2019 at 7:24
  • in addition - constructor isn't defined with void. Commented May 13, 2019 at 7:24

1 Answer 1

1

This is what a constructor will look like for ComplexNumbers with two int parameters:

public ComplexNumbers(int real, int imaginary){
}
Sign up to request clarification or add additional context in comments.

1 Comment

According to the guidelines ... Comments are not for answers: stackoverflow.com/help/privileges/comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.