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…
Question
Exhibit
Answer Area
Drag items
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:
- Visibility: Who can call this method? (
privatevspublic) - Binding: Does it need an object instance and class variables? (
instancevsstatic)
Placement 1 - MethodA → Private instance
Requirement recap: Only called from within the class; must access class (instance) variables.
| Criterion | Reasoning |
|---|---|
| Private | It is never called from outside the class. private enforces this encapsulation - nothing external can accidentally invoke it. |
| Instance | It 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.
| Criterion | Reasoning |
|---|---|
| Public | It is called from other locations throughout the application, so it must be externally accessible. private would prevent that. |
| Static | It 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,
privateis 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.
staticis the clean, correct choice.
Topics
Community Discussion
No community discussion yet for this question.
