fork download
  1. class Main {
  2. public static void main(String args []) {
  3. Texto t = new Texto("a b c d e");
  4. t.adiciona(new Frase("x y"));
  5. t.adiciona(" f g h i");
  6. System.out.println(t);
  7. }
  8. }
  9.  
  10. class Frase {
  11. String frase;
  12.  
  13. Frase(String frase) {
  14. this.frase = frase;
  15. }
  16. }
  17.  
  18. class Texto {
  19. String t;
  20.  
  21. Texto(String t) {
  22. this.t = t;
  23. }
  24.  
  25. void adiciona(Frase fra) {
  26. t = t.concat(fra.frase);
  27. }
  28.  
  29. void adiciona(String s) {
  30. t = t.concat(s);
  31. }
  32.  
  33. public String toString() {
  34. return t;
  35. }
  36. }
  37.  
  38. //https://pt.stackoverflow.com/q/542775/101
Success #stdin #stdout 0.08s 46860KB
stdin
Standard input is empty
stdout
a b c d ex y f g h i