Se invoca automáticamente cuando new crea un objeto de esa clase.
class A {
int x, y;
A() { x=0; y=0; } // el constructor
...
}
A a= new A();
a.Print(); // 0 0
class A {
int x, y;
A(int ix, int iy)
{ x=ix; y=iy; } // el constructor
...
}
A a= new A(1,2);
a.Print(); // 1 2
a= new A(); // error, hay que colocar
// los argumentos
a.A(1,2); // error, no se puede
// invocar el constructor
class A {
int x, y;
A() { x=0; y= 0; }
A(int ix, int iy)
{ x=ix; y=iy; }
A(A from)
{ x= from.x; y= from.y; }
...
}
A a1= new A();
a1.Print(); // 0 0
A a2= new A(1,2);
a2.Print(); // 1 2
A a3= new A(a2);
a3.Print(); // 1 2