Test 10 - Free Java SE 25 certification Mock test - Exam Code 1Z0-831-Oracle certified Java SE 25 Professional
Method overloading and variable arity parameters are two of the most contentious topics on the Java SE 25 Developer exam (1Z0-831). This free mock test takes them apart and shows you exactly how to work through them in a way that will allow you to determine which method the compiler will select and why.
Overload resolution proceeds through a series of phases. You'll learn how to apply them. The first phase is to look for an applicable method without boxing or varargs, using only identity, widening primitive or widening reference conversion. If that fails then boxing and unboxing are permitted. Only as a last resort is a variable arity method considered. The questions illustrate the competing phases, for instance calling a method with an int when you have overloads that take a long, Integer and Object and asking which one wins. The answer is the widening match (which is a bit of a surprise to many candidates).
Varargs get a lot of coverage. You'll see how a parameter declared as String... acts as an array within the method, how an empty call produces a zero length array rather than null and why only the final parameter can be varargs. Ambiguity is a classic exam trap (two overloads both taking varargs, or one taking a primitive varargs and one taking a boxed varargs) and can result in a compilation error if you call the method with the appropriate arguments.
Other items test what isn't actually overloading. Changing just the return type is illegal and changing just the thrown exception or just the parameter name has no effect. Overloads with null arguments, overloads with generic parameters that erase to the same signature and overloads with inherited methods from a superclass are all included. You'll also have a comparison between overloading (resolved at compile time from the reference type) and overriding (resolved at runtime from the object type).
Each explanation goes through the phase that applies and eliminates the others. That's the way to deal with the unfamiliar, rather than just memorising examples. Generics and boxing are going to throw some twists at you so you'll see overloads with List parameters and wrapper types. Keep your checklist, apply the phases and don't skip the step that eliminates the ambiguity. Take the test, go through and mark every single one where your first instinct was wrong and then go back and re-read the explanations for those. With a bit of practice, overload questions become just an exercise in going through a short checklist and that's a very comfortable place to be on exam day.

Time's up