Question: Suppose you want to add a constructor to Comp1ex that takes a double value as its argument and creates a Comp1ex number with that value
Suppose you want to add a constructor to Comp1ex that takes a double value as its argument and creates a Comp1ex number with that value as the real part (and no imaginary part). You write the following code:

But then the statement Comp1ex c = new Comp1ex(1.0); does not compile. Why? Solution: Constructors do not have return types, not even void. This code defines a method named Comp1ex, not a constructor. Remove the keyword void.
public void Complex (double real) { } re = real; im = 0.0;
Step by Step Solution
3.40 Rating (156 Votes )
There are 3 Steps involved in it
The provided code snippet is attempting to define a constructor for a class called Comp1ex that init... View full answer
Get step-by-step solutions from verified subject matter experts
