class TestFooBar {
public static Foo f = new Foo();
public static Foo f2;
public static Bar b = new Bar();
public static void main
(String [] args
) { for (int x=0; x<4; x++) {
f2 = getFoo(x);
}
}
static Foo getFoo(int y) {
if ( 0 == y % 2 ) {
return f;
} else {
return b;
}
}
}
class Bar extends Foo {
void react
() { System.
out.
print("Bar "); } }
class Foo {
void react
() { System.
out.
print("Foo "); } }
IGNsYXNzIFRlc3RGb29CYXIgewogICAgIHB1YmxpYyBzdGF0aWMgRm9vIGYgPSBuZXcgRm9vKCk7CiAgICAgcHVibGljIHN0YXRpYyBGb28gZjI7CiAgICAgcHVibGljIHN0YXRpYyBCYXIgYiA9IG5ldyBCYXIoKTsKCiAgICAgcHVibGljIHN0YXRpYyB2b2lkIG1haW4oU3RyaW5nIFtdIGFyZ3MpIHsKICAgICAgICAgZm9yIChpbnQgeD0wOyB4PDQ7IHgrKykgewogICAgICAgICAgICAgZjIgPSBnZXRGb28oeCk7CiAgICAgICAgICAgICAgICAgIH0KICAgIH0KICAgIHN0YXRpYyBGb28gZ2V0Rm9vKGludCB5KSB7CiAgICAgICAgaWYgKCAwID09IHkgJSAyICkgewogICAgICAgICAgICByZXR1cm4gZjsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgICByZXR1cm4gYjsKICAgICAgICB9CiAgICB9CiB9CgogY2xhc3MgQmFyIGV4dGVuZHMgRm9vIHsKICAgICB2b2lkIHJlYWN0KCkgeyBTeXN0ZW0ub3V0LnByaW50KCJCYXIgIik7IH0KIH0KCiBjbGFzcyBGb28gewogICAgIHZvaWQgcmVhY3QoKSB7IFN5c3RlbS5vdXQucHJpbnQoIkZvbyAiKTsgfQogfQoK