Bank.java
public class Bank{
int saveMoney;
int year;
double intrest;
public double computerInterest(){
interest=year*0.035*saveMoney;
return interest;
}
}
ConstructionBank.java
public class ConstructionBank extends bank{
double year;
public double computerInterest(){
super.year=(int)year;<--------------这里为什么super直接就获取了year的整数部分了呢????
double remainNumber=year-(int)year;
int day=(int)(remainNumber*1000);
interest=super.computerInterest()+day*0.0001*savedMoney;<----------一样的问题
System.out.printf("%d元存%d年零%d天\n"savedMoney,super.year,day);
return interest;
}
}
Example5_5.java{
public class Example5_5{
int amount=8000;
ConstructionBank Bank=new ConstructionBank();
bank.savedMoney=amount;
bank.year=5.216;
double interest=bank.computerInterest();
System.out.printf("利息是%5.3f元\n"interest);
}
}
这个程序只写了一部分,我只看懂了这个是继承类,year在子类中被重写了,这个也懂,super调用父类(super.year=(int)year;)也明白。可是
super.year=(int)year为什么直接调用了year的整数部分"5"呢
|