nerdexam
Microsoft

MB-500 · Question #270

Drag and Drop Question A company uses Dynamics 365 Finance. You create two methods in a class: - MethodA is called only from the class. MethodA is not called from other locations in the code. Within…

The correct answer is Private instance; Public static. Drag-and-Drop Explanation: Method Types in Dynamics 365 Finance (X++) --- The Two Decisions Per Method For each method, you need to answer two questions: 1. Visibility: Who can call this method? (private vs public) 2. Binding: Does it need an object instance and class…

Develop business logic

Question

Drag and Drop Question A company uses Dynamics 365 Finance. You create two methods in a class: - MethodA is called only from the class. MethodA is not called from other locations in the code. Within MethodA, you must access lass variables. - MethodB is called from other places in the app. MethodB does not need to instantiate the class or access the class variables. You need to implement the methods. Which method types should you use? To answer, drag the appropriate method types to the correct methods. Each method type may be used once, more than once, or not at all. You may need to drag the split bar between panes or scroll to view content. Answer:

Exhibit

MB-500 question #270 exhibit

Answer Area

Drag items

Private instancePublic staticPrivate static

Correct arrangement

  • Private instance
  • Public static

Explanation

Drag-and-Drop Explanation: Method Types in Dynamics 365 Finance (X++)


The Two Decisions Per Method

For each method, you need to answer two questions:

  1. Visibility: Who can call this method? (private vs public)
  2. Binding: Does it need an object instance and class variables? (instance vs static)

Placement 1 - MethodA → Private instance

Requirement recap: Only called from within the class; must access class (instance) variables.

CriterionReasoning
PrivateIt is never called from outside the class. private enforces this encapsulation - nothing external can accidentally invoke it.
InstanceIt must read/write class-level instance variables (fields declared on the class). Instance methods operate on a specific object and have full access to those fields. A static method has no this context and cannot reach instance variables.

Why not private static? A static method belongs to the class itself, not to any object, so it has no access to instance variables. Since MethodA requires instance variable access, static is ruled out.


Placement 2 - MethodB → Public static

Requirement recap: Called from other places in the app; does not need to instantiate the class or access class variables.

CriterionReasoning
PublicIt is called from other locations throughout the application, so it must be externally accessible. private would prevent that.
StaticIt does not need an object instance and does not access instance variables. static allows callers to invoke it directly on the class (ClassName::MethodB()) without creating an object first. This is both correct and more efficient.

Why not public instance? An instance method forces every caller to first instantiate the class - unnecessary overhead when no instance state is needed. Static is the right fit when a method is self-contained.


Why "Private static" Is Not Used Here

Private static would be the right choice for an internal utility/helper method that:

  • Is only called within the class (private), AND
  • Does not need instance variables (static)

Neither MethodA nor MethodB fits that profile:

  • MethodA needs instance variables → can't be static
  • MethodB is called externally → can't be private

Common Mistakes

  • Mixing up "class variables" and "static variables": Class variables in this context means instance fields declared on the class. These are only accessible to instance methods, not static ones.
  • Making MethodA public: Just because a method is inside a class doesn't mean it needs to be public. If it's only used internally, private is always preferred - it protects the class's internal logic.
  • Making MethodB an instance method: If a method doesn't use any object state, forcing callers to instantiate the class is wasteful. static is the clean, correct choice.

Topics

#X++ method modifiers#private instance method#static method#access control

Community Discussion

No community discussion yet for this question.

Full MB-500 Practice