我对类的继承有疑问。这是我的Java代码:
public class spaarRekening extends rekening{
private double rente;
public double getRente(){
return rente;
}
spaarRekening(String rN, int s, double d){
super(rN, s);
rente = d;
}
spaarRekening sR = new spaarRekening("456", 999999, 2.5);
}
public static class rekening implements rekeningIF{
int saldo;
static String rekeningNummer;
rekening(String rN, int s){
rekeningNummer = rN;
saldo = s;
}
public static String getRekeningNummer(){
return rekeningNummer;
}
public int getSaldo(){
return saldo;
}
}
我想让 spaarRekening 通过以下方式打印出来:
System.out.printf("Uw rekeningnummer is: %s\n", spaarRekening.getRekeningNummer());
但它打印出空值。为什么是这样?
谢谢。