Embercode
✕
Object-Oriented ProgrammingQuick quiz

Interfaces

6 questions. Covers Interface design with protocols and small base classes.

Questions 1 to 5 of 6

  1. 1. According to the interface design lesson, what should you look at first when you design an interface?
  2. 2. The TestStorage class in the fat interface example writes only save and load. What happens when the code runs TestStorage()?
  3. 3. Match each term from the interface design lesson to its meaning.

    Choose the matching item for each row.

  4. 4. Statement: a method in an abstract base class that no caller uses can stay, because nothing runs it and so it cannot cause a bug.
  5. 5. What does this program print? ``python class Rule: def __init__(self, test): self._test = test def passes(self, n): return self._test(n) def __and__(self, other): return Rule(lambda n: self.passes(n) and other.passes(n)) def __invert__(self): return Rule(lambda n: not self.passes(n)) big = Rule(lambda n: n >= 10) even = Rule(lambda n: n % 2 == 0) for n in [4, 11, 12, 15]: print(n, (big & even).passes(n), (~big).passes(n)) ``

5 question(s) left on this page.