Bird
Raised Fist0

Which of the following is the correct method signature for the execute method in a Command interface?

easy🧠 Conceptual Q12 of Q15
LLD - Behavioral Design Patterns — Part 1
Which of the following is the correct method signature for the execute method in a Command interface?
Avoid execute(String[] args);
Bvoid execute();
Cboolean execute(String commandName);
Dint execute(int commandId);
Step-by-Step Solution
Solution:
  1. Step 1: Recall Command interface basics

    The Command interface typically defines a simple execute() method without parameters to perform the action.
  2. Step 2: Analyze options

    The options with parameters (String[], int commandId, String commandName) or return types are not standard in Command pattern interfaces; the command object itself holds necessary data.
  3. Final Answer:

    void execute(); -> Option B
  4. Quick Check:

    Command execute method = void execute() [OK]
Quick Trick: Command execute usually has no parameters [OK]
Common Mistakes:
MISTAKES
  • Adding parameters to execute method unnecessarily
  • Confusing Command with other patterns that require arguments
  • Assuming execute returns a value

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes