var-arg has the lowest precedence. If a program has a choice, it will pretty much always choose anything else over a var-arg. The var-arg is the last resort, because it's least specific. It's like passing a Dog where a method is overloaded to accept either Object or Animal. Object is least specific, so it will choose Animal. Var-args behave the same way. They are the least specific, because if you want, you can pass 100 arguments.
Check out K&B study guide, it clearly states precedence rules. It's in Chapter 3, I believe. Not sure though. But it's in there.
Oracle Certified Professional: Java SE 6 Programmer
Oracle Certified Expert: Java EE 6 Web Component Developer
Oracle Certified Expert: Java EE 6 Enterprise JavaBeans Developer
arjun srivastava wrote:
why it should be the compiler error?
perhaps you are thinking static method can't be override but here method is overloaded.
remember varag is a loser in each and every case
I understand the confusion, because the call to printName(String, String) is ambiguous in this case. However, the post mentioned by Wouter Oet clearly states the compiler resolving this ambiguity by choosing the declared two-argument method over the varargs variant. In this case it is resolved by precedence of a fixed-number-of-arguments method over a method with varargs.