Bird
0
0

Which of the following is the correct method signature for the next() method in an iterator interface?

easy🧠 Conceptual Q12 of 15
LLD - Behavioral Design Patterns — Part 1

Which of the following is the correct method signature for the next() method in an iterator interface?

Adef next() -> void
Bdef next(self, index) -> Element
Cdef next(self) -> Element
Ddef next(self, element) -> bool
Step-by-Step Solution
Solution:
  1. Step 1: Recall the standard iterator method signature

    The next() method typically takes no parameters except the implicit self and returns the next element in the collection.
  2. Step 2: Analyze each option

    def next(self) -> Element matches the standard signature: it takes self and returns an element. Options B and D incorrectly add parameters, and C returns void which is incorrect.
  3. Final Answer:

    def next(self) -> Element -> Option C
  4. Quick Check:

    next() takes no args, returns element [OK]
Quick Trick: next() returns next element, no extra parameters [OK]
Common Mistakes:
MISTAKES
  • Adding parameters to next() method
  • Returning void instead of element
  • Confusing next() with hasNext() method

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes