nerdexam
Oracle

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.

Working with Methods and Encapsulation

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)
  • A
    86% (50)
  • C
    7% (4)
  • D
    2% (1)
  • E
    3% (2)
  • F
    2% (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.

ACompilation fails.Correct

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.

BThe third argument is given the value null.

Java does not automatically assign `null` to missing arguments; this is a compilation error.

CThe third argument is given the value void.

`void` is a keyword indicating the absence of a return type, not a value that can be assigned to an argument.

DThe third argument is given the value zero.

Java does not automatically assign `zero` to missing arguments; this is a compilation error.

EThe third argument is given the appropriate falsy value for its declared type.

Java does not automatically assign 'falsy' values to missing arguments; this is a compilation error.

FAn exception occurs when the method attempts to access the third argument.

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

#method invocation#compile-time errors#method parameters

Community Discussion

No community discussion yet for this question.

Full 1Z0-803 Practice