fork download
  1. import java.math.BigDecimal;
  2.  
  3. // tmp class, for test via main(),
  4. public class Main {
  5. public static void test() {
  6. SpecialEmployee se = new SpecialEmployee();
  7. System.out.printf("%.2f\n", se.getBonusMultiplier().floatValue());
  8. }
  9.  
  10. public static void main(String[] args) {
  11. test();
  12. }
  13. }
  14.  
  15. class RegularEmployee {
  16. private BigDecimal salary;
  17.  
  18. public void setSalary(BigDecimal salary) {
  19. this.salary = salary;
  20. }
  21.  
  22. public static BigDecimal getBonusMultiplier() {
  23. return new BigDecimal(".02");
  24. }
  25.  
  26. public BigDecimal calculateBonus() {
  27. return salary.multiply(getBonusMultiplier());
  28. }
  29.  
  30. /* ... presumably lots of other code ... */
  31. }
  32.  
  33. class SpecialEmployee extends RegularEmployee {
  34. public static BigDecimal getBonusMultiplier() {
  35. return new BigDecimal(".03");
  36. }
  37. }
Success #stdin #stdout 0.11s 320512KB
stdin
Standard input is empty
stdout
0.03