posted 22 years ago
Hi Folks,
Can anybody explain me why the following line in the code is Illegal?
class Complex {
private double real, imaginary;
public Complex (double r, double i) { real = r; imaginary = i;}
public Complex add (Complex c) {
return new Complex (real + c.real, imaginary + c.imaginary);
}
}
class Client {
void useThem () {
Complex c1 = new Complex (1,2);
Complex c2 = new Complex (3,4);
Complex c3 = c1.add(c2);
double d = c3.real; // Illegal!
}
}
what I don't understand is that c3 is an instance of class complex and we can have access to a private member of a class through an instance of that.What is difference between c3 and c1 and c2?
Thanks,
Samira