CS FundamentalsHardProduct-company placement · Python
What does this Template Method code print?
What does this Template Method code print?
class Base:
def run(self): return self.a() + self.b()
def a(self): return 'A'
def b(self): return 'B'
class Child(Base):
def a(self): return 'a' + super().a()
def b(self): return 'b'
class Grand(Child):
def b(self): return super().b() * 2
print(Grand().run())- A. aAB
- B. aAbb
- C. AbB
- D. bbaA
Correct answer: B. aAbb
run is inherited, but self is a Grand. a resolves to Child.a, giving 'a' + 'A'; b resolves to Grand.b, which calls Child.b ('b') and doubles it. Result: 'aA' + 'bb'.
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
- 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?
- A company debates a monorepo (all services in one repository) against one repository per service. Which statement is the strongest…