nerdexam
Microsoft

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…

Develop business logic

Question

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 parameter. You must implement an extension to: - Extend the calc method. - Prevent the standard code from running if the value of the input parameter is greater than 10. You need to implement the correct solution. Which code segment should you use? A. B. C. D.

Exhibits

MB-500 question #195 exhibit 1
MB-500 question #195 exhibit 2
MB-500 question #195 exhibit 3
MB-500 question #195 exhibit 4

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)
  • A
    63% (12)
  • B
    21% (4)
  • C
    11% (2)
  • D
    5% (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

#class extension#chain of command#method override#X++ extension

Community Discussion

No community discussion yet for this question.

Full MB-500 Practice