このコードを実行すると、1500の代わりに0が返されるのはなぜですか?Java - なぜ子は親変数の継承をしませんか?
public class Department {
private double rate = 0.0;
public Department {
}
public getRate(){
return rate;
}
public setRate(){
rate = 1 + 2;
}
}
public class Employe extends Department {
private double salary = 0;
public Employe {
}
public calculateSalary(){
salary = getRate() * 500;
}
}
public static void main(String[] args) throws IOException {
Department department = New Department();
department.setRate();
Employe employe = new Employe();
System.out.println(employe.calculateSalary());
}
コードはまったくコンパイルされますか?構文エラーがかなりあります。たとえば、コンストラクター定義に括弧がありません。また、戻り値の型も指定されていません。 –