🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: SOLID Principles: all 10 questions

Quiz: SOLID Principles · Question 7 of 10

What does this print? (code)

What does this print?

class Sender:
    def send(self, text):
        raise NotImplementedError

class Fake(Sender):
    def __init__(self):
        self.box = []
    def send(self, text):
        self.box.append(text)

class Alert:
    def __init__(self, sender):
        self.sender = sender
    def check(self, temp):
        if temp > 40:
            self.sender.send(f'hot {temp}')

f = Fake()
a = Alert(f)
for t in [38, 42, 45]:
    a.check(t)
print(len(f.box), f.box[-1])
  1. A.3 hot 45
  2. B.1 hot 42
  3. C.2 hot 45
  4. D.NotImplementedError
Answer & explanation

Correct answer: 2 hot 45

Only 42 and 45 are above 40; the injected Fake records both, the last being "hot 45".

Can you get the rest right without peeking?

Take the timed Quiz: SOLID Principles quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →