Suppose you want to add a constructor to Comp1ex that takes a double value as its argument
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 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.
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Related Book For
Introduction To Programming In Java An Interdisciplinary Approach
ISBN: 9780672337840
2nd Edition
Authors: Robert Sedgewick, Kevin Wayne
Question Posted: