class Empleado_test3 {
private String nombre = new String();
private double sueldo;
private Date altaContrato;
// ELABORACIÓN DEL MÉTODO CONSTRUCTOR 1
public Empleado_test3(String nombre, double sueldo, int agno, int mes, int dia) {
this.nombre = nombre;
this.sueldo = sueldo;
GregorianCalendar calendario = new GregorianCalendar(agno, mes-1, dia);
this.altaContrato = calendario.getTime();
}
// ELABORACIÓN DEL MÉTODO CONSTRUCTOR 2
public Empleado_test3(String nombre) {
this.nombre = nombre;
}
// GETTER -- sueldo
public double getSueldo() {
return sueldo;
}
Why I can cast getSueldo() from the principal class? I mean, if I instance a object and I attach only the name of the employee, the class launch the second constructor method and "sueldo" will not be initialized. Normally, if I attempt to use a variable that hasn't have been initialized, Java returns an error. In this case Java assigns the value zero to the variable sueldo.