Advertisement
STANAANDREY

liskow substitution

Sep 19th, 2023
1,051
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.86 KB | None | 0 0
  1.  
  2. class Employee {
  3.     public int computeSalary() {
  4.         return 1000;
  5.     }
  6.     final void doTheJob() {
  7.         System.out.println("WORK!");
  8.     }
  9. }
  10.  
  11. interface IEmpWithBonus {
  12.     default int getBonusSalary() {
  13.         return 100;
  14.     }
  15. }
  16.  
  17. class PermanentEmployee extends Employee implements IEmpWithBonus {
  18.     @Override
  19.     public int computeSalary() {
  20.         return super.computeSalary() * 2;
  21.     }
  22. }
  23.  
  24. class Intern extends Employee {
  25.     @Override
  26.     public int computeSalary() {
  27.         return super.computeSalary() / 2;
  28.     }
  29. }
  30.  
  31. public class Main {
  32.  
  33.     public static void main(String[] args) {
  34.         PermanentEmployee permanentEmployee = new PermanentEmployee();
  35.         System.out.println(permanentEmployee.getBonusSalary());
  36.         Intern intern = new Intern();
  37.         System.out.println(intern.computeSalary());
  38.     }
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement