MB-500 · Question #195
A company uses Dynamics 365 Finance. You implement an extension of a method named calc in ClassA. The calc method: - Accepts an integer as an input parameter. - Returns an integer as an output…
The correct answer is A. public int calc(int _value) { if (_value > 10) { throw error('The value cannot be greater than 10.'); } int ret = next calc(_value); return ret; }. Option A correctly checks the input value before calling next calc(_value), which is the X++ keyword that invokes the original (standard) method. By throwing an error first when _value > 10, the standard code is never reached, satisfying the requirement - and for valid inputs…
Question
Exhibits
Options
- Apublic int calc(int _value) { if (_value > 10) { throw error('The value cannot be greater than 10.'); } int ret = next calc(_value); return ret; }
- Bpublic int calc(int _value) { if (_value > 10) { throw error('The value cannot be greater than 10.'); } }
- Cpublic int calc(int _value) { int ret = next calc(_value); if (_value > 10) { throw error('The value cannot be greater than 10.'); } return ret; }
- Dpublic int calc(int _value) { int ret; if (_value <= 10) { ret = next calc(_value); } return ret; }
How the community answered
(19 responses)- A63% (12)
- B21% (4)
- C11% (2)
- D5% (1)
Explanation
Option A correctly checks the input value before calling next calc(_value), which is the X++ keyword that invokes the original (standard) method. By throwing an error first when _value > 10, the standard code is never reached, satisfying the requirement - and for valid inputs, the result of the original method is captured and returned properly.
Option B never calls next calc() at all, meaning the standard code never runs for any input value, and it also lacks a return statement, which won't compile for a method that must return an integer. Option C calls next calc(_value) before the condition check, so the standard code already executes even when the value exceeds 10 - too late to prevent it. Option D silently returns the default integer value of 0 when the input is invalid rather than signaling an error, which is incorrect behavior and hides the problem from the caller.
Memory tip: In X++ extensions, think of next as the "go ahead" command to the standard code - your guard clause must come before next, not after, and omitting next entirely breaks the extension chain for all valid inputs.
Topics
Community Discussion
No community discussion yet for this question.



