作业问题
Topic source如果想要删掉static,需要先定义类,具体代码如下:
public class Main{
public static void main(String[] args) {
// 给一个有普通收入、工资收入和享受国务院特殊津贴的小伙伴算税:
Income[] incomes = new Income[] {
new Income(3000),
new Salary(7500),
new StateCouncilSpecialAllowance(15000)
};
Main calculator = new Main(); // 创建test1的一个实例
System.out.println(calculator.totalTax(incomes)); // 通过实例调用totalTax方法
}
public double totalTax(Income... incomes) { // totalTax现在是一个实例方法
double total = 0;
for (Income income : incomes) {
total = total + income.getTax();
}
return total;
}
}
//后续代码相同
- 1
空森森森_
为什么totalTax得是static方法