fork download
  1. class TestFooBar {
  2. public static Foo f = new Foo();
  3. public static Foo f2;
  4. public static Bar b = new Bar();
  5.  
  6. public static void main(String [] args) {
  7. for (int x=0; x<4; x++) {
  8. f2 = getFoo(x);
  9. }
  10. }
  11. static Foo getFoo(int y) {
  12. if ( 0 == y % 2 ) {
  13. return f;
  14. } else {
  15. return b;
  16. }
  17. }
  18. }
  19.  
  20. class Bar extends Foo {
  21. void react() { System.out.print("Bar "); }
  22. }
  23.  
  24. class Foo {
  25. void react() { System.out.print("Foo "); }
  26. }
  27.  
  28.  
Success #stdin #stdout 0.07s 32324KB
stdin
Standard input is empty
stdout
Standard output is empty