?? payroll.java
字號:
interface Employee
{
public int salary();
public int bonus();
}
class Manager implements Employee
{
private static final int mgrSal = 40000;
private static final int mgrBonus = 0;
public int salary()
{
return mgrSal;
}
public int bonus()
{
return mgrBonus;
}
}
class Programmer implements Employee
{
private static final int prgSal = 50000;
private static final int prgBonus = 10000;
public int salary()
{
return prgSal;
}
public int bonus()
{
return prgBonus;
}
}
class Payroll
{
public int calcPayroll(Employee emp)
{
//Calculate the bonus. No instanceof check needed.
return emp.salary() + emp.bonus();
}
public static void main(String args[])
{
Payroll pr = new Payroll();
Programmer prg = new Programmer();
Manager mgr = new Manager();
System.out.println("Payroll for Programmer is " +
pr.calcPayroll(prg));
System.out.println("Payroll for Manager is " +
pr.calcPayroll(mgr));
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -