MB-500 · Question #246
Drag and Drop Question A company uses Dynamics 365 Finance. You must implement three classes with the following requirements: - Variables in ClassA must be accessible from ClassA and its child…
The correct answer is ClassA: Protected; ClassC: Private. X++ Variable Modifiers - Explanation The Three Modifiers | Modifier | Accessible From | |---|---| | public | Any class, anywhere | | protected | The class itself + all child (subclass) classes | | private | Only the class itself - nobody else | --- Placement 1: ClassA →…
Question
Exhibit
Answer Area
Drag items
Correct arrangement
- ClassA: Protected
- ClassC: Private
Explanation
X++ Variable Modifiers - Explanation
The Three Modifiers
| Modifier | Accessible From |
|---|---|
public | Any class, anywhere |
protected | The class itself + all child (subclass) classes |
private | Only the class itself - nobody else |
Placement 1: ClassA → Protected
Requirement: Variables must be accessible from ClassA and its child classes, but not from unrelated classes.
This is precisely what protected does. ClassB inherits from ClassA, so protected variables on ClassA are visible inside ClassB automatically - no separate declaration needed for ClassB. Using public would fail because it would expose the variables to every class, violating the "not from other classes" constraint. Using private would fail because ClassB (a child) couldn't access them.
Placement 2: ClassC → Private
Requirement: Variables must only be accessible within ClassC itself.
This is precisely what private does - it locks access to the declaring class only. Since ClassC has no parent or child relationship, there's nothing to inherit to or from, making private the correct and only appropriate choice.
Why ClassB Has No Answer
ClassB is not listed as requiring its own variable modifier. It's a consumer of ClassA's protected variables, not a source of new access-controlled variables in this scenario.
Common Misconceptions
- Confusing
protectedwithprivate: A common mistake is thinking "restricted = private," butprotectedis the right "restricted-but-inheritable" choice. - Using
publicfor ClassA: Public satisfies the "child class can access it" part but breaks the "not from other classes" requirement. - Thinking ClassB needs an answer: ClassB inherits; it doesn't redeclare. The question is about where variables are defined, not where they're used.
Topics
Community Discussion
No community discussion yet for this question.
