1Z0-803 · Question #88
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. Compilation fails.. Java requires strict adherence to method signatures; calling a method with an incorrect number of arguments results in a compilation error. The compiler detects this mismatch before execution.
Question
A method is declared to take three arguments. A program calls this method and passes only two arguments. What is the results?
Options
- ACompilation 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
(58 responses)- A86% (50)
- C7% (4)
- D2% (1)
- E3% (2)
- F2% (1)
Why each option
Java requires strict adherence to method signatures; calling a method with an incorrect number of arguments results in a compilation error. The compiler detects this mismatch before execution.
Java's compiler enforces strict type checking and argument count matching for method calls. If a method is called with fewer arguments than it is declared to accept, the compiler will detect this discrepancy and produce a compilation error, preventing the program from running.
Java does not automatically assign `null` to missing arguments; this is a compilation error.
`void` is a keyword indicating the absence of a return type, not a value that can be assigned to an argument.
Java does not automatically assign `zero` to missing arguments; this is a compilation error.
Java does not automatically assign 'falsy' values to missing arguments; this is a compilation error.
An exception occurs at runtime, but in this scenario, the program would fail to compile before runtime, so no exception could be thrown.
Concept tested: Java method argument matching at compile time
Source: https://docs.oracle.com/javase/tutorial/java/javaOO/methods.html
Topics
Community Discussion
No community discussion yet for this question.