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)- A. ['core'] ['mp3', 'wav']
- B. ['mp3', 'core', 'mp4', 'wav'] ['mp3', 'wav']
- C. ['core', 'mp4'] ['mp3', 'wav']
- 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.
Practise more Software Engineering, Git and Cloud Basics questionsSoftware Engineering, Git and Cloud Basics: notes and key points
More Software Engineering, Git and Cloud Basics questions
- What does this Template Method code print? python class Base: def run(self): return self.a() + self.b() def a(self): return 'A' def…
- Why do many agile teams estimate story points on a Fibonacci-like scale (1, 2, 3, 5, 8, 13, …) instead of 1 to 10?
- Match each risk response with an example. P. Avoid Q. Transfer R. Mitigate S. Accept 1. Buy fixed-price insurance against data-centre…
- In an ATAM architecture evaluation, encrypting all messages between services improves security but raises latency. In ATAM terms, what is…
- A team rebases a long-lived branch every day and keeps resolving the same conflict in config.yml by hand. Which Git feature can do this…
- A CI job clones a huge repository with git clone --filter=blob:none. Which statement is correct?