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.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *