Let's say I have
Interface A {
public void doSomething(Object a);
}
Interface B {
public void doSomething(Foo b);
}
and
Class C implements A, B {
public void doSomething(Object a) { print("a"); }
public void doSomething(Foo b) { print("b"); }
}
I guess calling new C.doSomething(new Foo()); will print "b", even though Foo extends Object.
but what about if I want a common behavior from sub-methods:
Class C implements A, B {
public void doSomething(Object a) { print("common behavior from " + a ); }
public void doSomething(Foo b) { doSomething((Object) b); }
public void doSomething(Bar c) { doSomething((Object) c);}
}
Will that work when I call doSomething with Foo and Bar or will they end up in an infinite loop because at the end doing ((Object) c) instanceof Bar == true?
How does Java defines which method to call?