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