Consider the class
public class Complex
{
private double x;
private double y;
public Complex(double x , double y)
{
this.x = x;
this.y = y;
}
}
That represents a Complex number x + y*i
, where i
is the imaginary part.
I have the following main :
public static void main(String args[])
{
Complex p1 = new Complex(1 , 2); // ok
Complex p2 = new Complex(3 , 4); // ok
Complex p3 = p1 + p2; // Not ok , doesn't compile
}
The third line Complex p3 = p1 + p2;
doesn't compile , since there is no operator overloading
in Java . It would have worked in C++ .
Any way around this (in Java) ?
Much appreciated