Answer the question
In order to leave comments, you need to log in
How to correctly call the void method in main?
this is how i try to call :
System.out.println(real.increment(imaginary));
here is the error :
error: Class names, 'javac', are only accepted if annotation processing is explicitly requested
ComplexMain.java:14: error: incompatible types: void cannot be converted to Complex
Complex res = real.increment(imaginary);
System.out.println(increment(imaginary));
Answer the question
In order to leave comments, you need to log in
Error in the line
Complex res = real.increment(imaginary);
and in
System.out.println(real.increment(imaginary));
the same error. The increment method returns void, and changes the internal value. void cannot be assigned to anything, and cannot be passed anywhere. You can consider it "emptiness", "nothing". The void method does not return anything, so its return value cannot be assigned anywhere.
You need to split this into different lines:
real.increment(imaginary);
System.out.println(real);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question