fork download
  1. class Outer {
  2. String name;
  3. public Outer(String name) {
  4. this.name = name;
  5. }
  6.  
  7. public class Inner {
  8. public String toString() {
  9. return "I belong to " + Outer.this.name;
  10. }
  11. }
  12.  
  13. void f() {
  14. System.out.println(new Inner());
  15. }
  16.  
  17. void g(Outer a) {
  18. System.out.println(a.new Inner());
  19. }
  20. }
  21.  
  22. class Main {
  23. public static void main(String[] args) {
  24. Outer x = new Outer("x");
  25. Outer y = new Outer("y");
  26. x.f();
  27. x.g(y);
  28. }
  29. }
  30.  
Success #stdin #stdout 0.03s 245632KB
stdin
Standard input is empty
stdout
I belong to x
I belong to y