//主类
public class Main {
public static void main(String[] args) {
// TODO: 给一个有工资收入和稿费收入的小伙伴算税:
Income[] incomes = new Income[] { new Income(3000), new SalaryIncome(7500), new RoyaltyIncome(12000) };
double total = 0;
// TODO:
for (Income income : incomes) {
total += income.getTax();
}
System.out.println(total);
}
}
//稿费类
public class RoyaltyIncome extends Income {
public RoyaltyIncome(double income) {
super(income);
// TODO Auto-generated constructor stub
}
// TODO
@Override
public double getTax() {
return income * 0.2;
}
}
//结果应该为 3200
Awdcuhhk