CS FundamentalsVery hardProduct-company placement · Python

What does this plugin-registry code print?

What does this plugin-registry code print?
class Plugin:
    registry = []
    def __init__(self, name): self.registry.append(name)

class Audio(Plugin):
    registry = []

class Video(Plugin): pass

Audio('mp3'); Plugin('core'); Video('mp4'); Audio('wav')
print(Plugin.registry, Audio.registry)
  1. A. ['core'] ['mp3', 'wav']
  2. B. ['mp3', 'core', 'mp4', 'wav'] ['mp3', 'wav']
  3. C. ['core', 'mp4'] ['mp3', 'wav']
  4. D. ['core', 'mp4'] []

Correct answer: C. ['core', 'mp4'] ['mp3', 'wav']

self.registry looks up the class chain: Audio defines its own list, so 'mp3' and 'wav' go there, while Video has none and shares Plugin's list, which gets 'core' and 'mp4'. Forgetting the shared lookup gives ['core'] alone.

More Software Engineering, Git and Cloud Basics questions

Exams that ask this topic