Bird
0
0

Which of the following is the correct method signature for a visitor interface method visiting an element called ElementA?

easy🧠 Conceptual Q12 of 15
LLD - Behavioral Design Patterns — Part 2
Which of the following is the correct method signature for a visitor interface method visiting an element called ElementA?
Avoid accept(ElementA element);
Bvoid acceptVisitor(ElementA visitor);
Cvoid visitElementA();
Dvoid visit(ElementA element);
Step-by-Step Solution
Solution:
  1. Step 1: Recall Visitor interface method naming

    The visitor interface defines methods named visit with the element type as parameter.
  2. Step 2: Match correct signature

    The correct signature is void visit(ElementA element); to visit ElementA.
  3. Final Answer:

    void visit(ElementA element); -> Option D
  4. Quick Check:

    Visitor method = visit(Element) [OK]
Quick Trick: Visitor methods are named visit(Element) [OK]
Common Mistakes:
MISTAKES
  • Confusing accept and visit method names
  • Using no parameters in visit method
  • Swapping visitor and element in parameters

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes