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

Quiz: Design Patterns · Question 7 of 10

What does this print? (code)

What does this print?

def standard(km): return 30 + 5 * km
def express(km): return 60 + 8 * km

class Checkout:
    def __init__(self, fee): self.fee = fee
    def total(self, cart, km): return cart + self.fee(km)

c = Checkout(standard)
a = c.total(200, 2)
c.fee = express
b = c.total(200, 2)
print(a, b)
  1. A.240 276
  2. B.240 240
  3. C.276 276
  4. D.230 268
Answer & explanation

Correct answer: 240 276

standard: 200 + 30 + 10 = 240; after swapping the strategy, express: 200 + 60 + 16 = 276.

Can you get the rest right without peeking?

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

Start the quiz →