1Z0-808 · Question #72
A method is declared to take three arguments. A program calls this method and passes only two arguments. What is the results?
The correct answer is A. A compilation fails. In Java (and most statically-typed compiled languages), the compiler enforces that every method call provides exactly the number of arguments matching the method's signature - passing too few arguments is a compile-time error, not a runtime one. Options B, C, D, and E are wrong…
Question
Options
- AA compilation fails.
- BThe third argument is given the value null.
- CThe third argument is given the value void.
- DThe third argument is given the value zero.
- EThe third argument is given the appropriate falsy value for its declared type.
- FAn exception occurs when the method attempts to access the third argument.
How the community answered
(52 responses)- A94% (49)
- E4% (2)
- F2% (1)
Explanation
In Java (and most statically-typed compiled languages), the compiler enforces that every method call provides exactly the number of arguments matching the method's signature - passing too few arguments is a compile-time error, not a runtime one. Options B, C, D, and E are wrong because the compiler never gets the chance to run the code and assign default values; there is no implicit default-filling behavior for missing arguments in Java. Option F is wrong for the same reason - the program never reaches runtime execution, so no exception can be thrown. Memory tip: Think of the compiler as a strict gatekeeper - it checks the "guest list" (method signature) at the door before anyone enters the party (runtime); if the argument count doesn't match, you never get in.
Topics
Community Discussion
No community discussion yet for this question.