fork download
  1. abstract class Customer {
  2. private int price;
  3. public void setPrice(int price) {
  4. this.price = price;
  5. }
  6. public int getPrice() {
  7. return price;
  8. }
  9. }
  10.  
  11. class RegularCustomer extends Customer {
  12. public RegularCustomer() {
  13. setPrice(100);
  14. }
  15. }
  16. class HandicappedCustomer extends Customer {
  17. public HandicappedCustomer() {
  18. setPrice(0);
  19. }
  20. }
  21.  
  22. public class Main {
  23. public static void main (String[] args) {
  24. Customer a = new HandicappedCustomer();
  25. Customer b = new RegularCustomer();
  26. System.out.println(a.getPrice());
  27. System.out.println(b.getPrice());
  28. }
  29. }
  30.  
Success #stdin #stdout 0.07s 380160KB
stdin
Standard input is empty
stdout
0
100