Junior — Middle
Describe a situation where you applied inheritance principles in object-oriented programming.
sobes.tech AI
Answer from AI
In one of my test automation projects, I created a base class TestBase that contained common methods for initializing the browser, setting up the environment, and cleaning up after tests. Then, for each type of test (for example, functional, integration), I created subclasses that inherited from this base class and extended it with specific logic. This approach helped avoid code duplication and simplified test maintenance.
class TestBase:
def setup(self):
print("Initializing browser")
def teardown(self):
print("Closing browser")
class FunctionalTest(TestBase):
def run_test(self):
self.setup()
print("Running functional test")
self.teardown()
ft = FunctionalTest()
ft.run_test()