fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone {
  9. public static void main (String[] args) throws java.lang.Exception {
  10. A a = new A();
  11. C c = a.getC();
  12. c.setYo("Bo");
  13.  
  14. a.getC().printYo();
  15. }
  16.  
  17. static class A {
  18. private C c;
  19.  
  20. // a constructor that assigns to the instanceVariable.
  21. public A() {
  22. this.c = new C();
  23. }
  24.  
  25. public C getC() {
  26. return this.c;
  27. }
  28. }
  29.  
  30. static class C {
  31. public String yo;
  32.  
  33. public C() {
  34. this.yo = "yo";
  35. }
  36.  
  37. public void setYo(String changeYo) {
  38. this.yo = changeYo;
  39. }
  40.  
  41. public void printYo() {
  42. System.out.println(yo);
  43. }
  44. }
  45. }
Success #stdin #stdout 0.1s 320576KB
stdin
Standard input is empty
stdout
Bo