fork(1) download
  1. class Test {
  2. public static void main(String[] args) {
  3. Foo f = new Foo();
  4. // Would not compile: System.out.println(f.hi);
  5. Foo.Bar b = f.method();
  6. System.out.println(b.hi);
  7. }
  8. }
  9. class Foo
  10. {
  11. public Bar method() {
  12. return new Bar("b");
  13. }
  14.  
  15. public class Bar
  16. {
  17. private String barbar;
  18.  
  19. public String hi = "Hi there";
  20.  
  21. public Bar( String b ) { barbar = b; }
  22. }
  23.  
  24. class Meh
  25. {
  26. private void method() {
  27. Bar b = new Bar("BAR!");
  28.  
  29. System.out.println( b.barbar );
  30. }
  31. }
  32. }
Success #stdin #stdout 0.1s 320576KB
stdin
Standard input is empty
stdout
Hi there