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

Quiz: Object Relationships · Question 8 of 10

What does this print? (code)

What does this print?

class Player:
    def __init__(self, name): self.name = name

class Team:
    def __init__(self, players): self.players = players

p = Player("Mithali")
t1 = Team([p])
t2 = Team([p])
t1.players[0].name = "Mithali Raj"
print(t2.players[0].name)
  1. A.Mithali
  2. B.Mithali Raj
  3. C.AttributeError
  4. D.None
Answer & explanation

Correct answer: Mithali Raj

Both teams aggregate the same Player object, so a change through t1 is seen through t2.

Can you get the rest right without peeking?

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

Start the quiz →