class Complex1 {
public int real, imaginary;
public Complex1 (int r, int i) {
real = r;
imaginary = i;
}
public Complex1 add(Complex1 c) {
return new Complex1 (real + c.real, imaginary + c.imaginary);
}
void Output() {
System.out.println("Values : " + real+" "+imaginary);
//System.out.println("Values c2: " + c2.real+" "+c2.imaginary);//illegal
//System.out.println("Values c3: " + c3.real+" "+c3.imaginary);//illegal
}
}
class subComplex1 extends Complex1 {
subComplex1 (int r, int i) {
real = r;
imaginary = i;
}
}
class Complex2 {
void useThem() {
Complex1 c1 = new Complex1(1,2);
Complex1 c2 = new Complex1(3,4);
Complex1 c3 = c1.add(c2);
c1.Output();
c2.Output();
//c2.Output();
//double d = c3.real;
}
}
class Client {
public static void main (
String args[]) {
Complex2 com2 = new Complex2();
com2.useThem();
}
}
While compiling I am getting an error saying that no Constructor matching Complex() found in class Complex1.
Could anyone explain why cann't I have a constructor for a subclass and the usage?.
Thanks,
Thunthu