You're working on a project where a derived class Laptop inherits from two base classes: Computer and PortableDevice. Both base classes have a method named power_on(). If you call power_on() from a Laptop object without any specifications, which method will be invoked?
- An error will occur due to ambiguity in method names in the multiple inheritance scenario
- The power_on() method of the Computer class will be invoked
- The power_on() method of the Laptop class will be invoked
- The power_on() method of the PortableDevice class will be invoked
In the case of multiple inheritance, if two base classes have a method with the same name, the method of the first base class listed in the inheritance declaration is invoked. In this scenario, calling power_on() from a Laptop object without specifications will invoke the power_on() method of the Computer class.
Loading...
Related Quiz
- You are implementing a caching mechanism. You need a data structure that removes the least recently added item when the size limit is reached. Which built-in Python data structure would you use?
- How does Python interpret the following line: # This is a comment?
- How would you optimize a Python function that is found to be CPU-bound during profiling?
- The counterpart to the @property decorator for setting the value of an attribute is _______.
- How would you test a function that does not return a value, but prints something out, using unittest?