fork download
  1. import java.util.*;
  2.  
  3. interface Showable
  4. {
  5. public String show();
  6. }
  7.  
  8. class Int implements Showable
  9. {
  10. private int n;
  11.  
  12. public Int(int nn)
  13. {
  14. n = nn;
  15. }
  16.  
  17. public String show()
  18. {
  19. return Integer.toString(n);
  20. }
  21. }
  22.  
  23. class Person implements Showable
  24. {
  25. private String name;
  26.  
  27. private int age;
  28.  
  29. public Person(String n, int a)
  30. {
  31. name = n;
  32. age = a;
  33. }
  34.  
  35. public String show()
  36. {
  37. return "name: " + name + "age: " + Integer.toString(age);
  38. }
  39. }
  40.  
  41. class Ideone
  42. {
  43. public static void main (String[] args) throws java.lang.Exception
  44. {
  45. List<Showable> lsh = new ArrayList<Showable>();
  46. lsh.add(new Int(42));
  47. lsh.add(new Person("Jhon Doe", 22));
  48. }
  49. }
  50.  
Success #stdin #stdout 0.09s 320512KB
stdin
Standard input is empty
stdout
Standard output is empty