Hi Sergey,
Determining which overloaded method will be invoked is one of the hardest things on both the OCAJP7 as the OCPJP7 exams. On the OCPJP7 exam these question will even be a lot harder/trickier
There are a number of rules you need to know and which can be demonstrated using a few simple code snippets.
Let's assume the
main method is always the same in every example:
Here are a few examples. All these examples will compile successfully. It's up to you to determine which method will be invoked (before confirming your answer by compiling and running the examples).
Phew! That's a lot of examples
If you have answered all above examples correctly, you'll be able to have a list of rules used by the compiler to determine which overloaded method to execute. And sometimes (as in your example) the compiler can't determine which overloaded method to use (mostly when autoboxing and var-args are combined).
(Disclaimer: both autboxing/unboxing and var-args are not on the OCAJP7 exam. I added a few examples just for completeness. You'll definitely need to know if you'll take the OCPJP7 exam)