Advertisement
Guest User

Untitled

a guest
May 14th, 2021
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.69 KB | None | 0 0
  1. abstract class Person {
  2.     String name;
  3.  
  4.     public Person(String name) {
  5.         this.name = name;
  6.     }
  7.  
  8.     int foo () {
  9.         return 0;
  10.     }
  11. }
  12.  
  13. class Employee extends Person {
  14.  
  15.     public Employee(String name) {
  16.         super(name);
  17.     }
  18.  
  19.     @Override
  20.     int foo() {
  21.         return 1;
  22.     }
  23. }
  24.  
  25. class Client extends Person {
  26.  
  27.     public Client(String name) {
  28.         super(name);
  29.     }
  30.  
  31.     @Override
  32.     int foo() {
  33.         return 2;
  34.     }
  35. }
  36.  
  37. public class Main {
  38.  
  39.     public static void main(String[] args) {
  40.         Person Tomek = new Employee("Tomek");
  41.         Person Adam = new Client("Adam");
  42.  
  43.         System.out.println(Adam.foo());
  44.     }
  45. }
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement