Difficulty: Easy
Correct Answer: Incorrect
Explanation:
Introduction / Context: This question distinguishes between two common operation categories in OO design: constructors and mutators. Mislabeling these can blur the life cycle of objects and lead to misunderstandings in both design documentation and code reviews.
Given Data / Assumptions:
Concept / Approach: A constructor is an operation invoked when a new object is created; it initializes the new instance’s state. After creation, operations that change an object’s state are typically called mutators, setters, or commands. Therefore, calling any state-altering operation a “constructor” is incorrect: constructors are specifically about creation and initial setup, not ongoing mutations of existing objects.
Step-by-Step Solution:
Define constructor: operation executed once at instantiation to initialize state.Define mutator: operation that modifies state after the object already exists.Recognize the statement conflates these roles.Conclude that the statement is incorrect.Verification / Alternative check: Inspect languages like Java, C++, C#, or Python: constructors (or init) run at creation; mutator methods (for example, setBalance, applyDiscount) change state later. UML mirrors this practice in sequence and class diagrams.
Why Other Options Are Wrong:
Common Pitfalls: Treating heavy initialization as general mutation; forgetting to keep constructors side-effect free beyond initialization, which complicates testing and invariants.
Final Answer: Incorrect
Discussion & Comments