fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. class Ideone
  6. {
  7. interface Animal {
  8. public void eat();
  9. }
  10.  
  11. interface Dog extends Animal {
  12. public void woof();
  13. }
  14.  
  15. interface Cat extends Animal {
  16. void meow();
  17. }
  18.  
  19. static class Poppy implements Dog {
  20. public void eat() {}
  21. public void woof() {}
  22. }
  23.  
  24. static class Dazy implements Cat {
  25. public void eat() {}
  26. public void meow() {}
  27. }
  28.  
  29. static class Container {
  30. Animal animal;
  31.  
  32. public Container(Animal animal) {
  33. this.animal = animal;
  34. }
  35. }
  36.  
  37. static void replace(Container container) {
  38. container.animal = new Poppy();
  39. }
  40.  
  41. public static void main (String[] args) throws java.lang.Exception
  42. {
  43. Cat cat = new Dazy();
  44. Container container = new Container(cat);
  45. replace(container);
  46. }
  47. }
Success #stdin #stdout 0.1s 32508KB
stdin
Standard input is empty
stdout
Standard output is empty