fork download
  1. import java.util.*;
  2.  
  3. class Ideone {
  4.  
  5. public static void main (String[] args) {
  6. add(new Player("Vova"));
  7. add(new YourEX("Vika"));
  8. add(new YourEX("Masha"));
  9. add(new YourEX("Dasha"));
  10. add(new Player("Pasha"));
  11. add(new Player("Petya"));
  12. }
  13.  
  14. private static void add(StaticEntity s) {
  15. System.out.print(s.getName());
  16. System.out.println(" is Static");
  17. }
  18.  
  19. private static void add(DynamicEntity entity) {
  20. System.out.print(entity.getName());
  21. System.out.println(" is Dynamic");
  22. }
  23.  
  24. interface Entity {
  25. String getName();
  26. }
  27. interface StaticEntity extends Entity {}
  28. interface DynamicEntity extends Entity {}
  29.  
  30. static class BaseEntity implements Entity {
  31.  
  32. private final String name;
  33.  
  34. public BaseEntity(String name) {
  35. this.name = name;
  36. }
  37.  
  38. @Override
  39. public String getName() {
  40. return name;
  41. }
  42. }
  43.  
  44. static class Player extends BaseEntity implements DynamicEntity {
  45.  
  46. public Player(String name) {
  47. super(name);
  48. }
  49. }
  50.  
  51. static class YourEX extends BaseEntity implements StaticEntity {
  52.  
  53. public YourEX(String name) {
  54. super(name);
  55. }
  56. }
  57. }
Success #stdin #stdout 0.07s 2841600KB
stdin
Standard input is empty
stdout
Vova is Dynamic
Vika is Static
Masha is Static
Dasha is Static
Pasha is Dynamic
Petya is Dynamic