To answer this question, you need to understand the concept of inheritance.
Inheritance is a fundamental concept in object-oriented programming (OOP) that allows a class to inherit properties and methods from another class. It creates a parent-child relationship between classes, where the child class inherits the attributes and behaviors of the parent class.
Now let's go through each option to understand why it is correct or incorrect:
Option A) Reuse and modify existing modules of code - This option is correct because inheritance allows us to reuse and modify existing code by inheriting the properties and methods of a parent class. We can create new classes based on existing ones, without having to rewrite the code from scratch. This promotes code reusability and reduces redundancy.
Option B) Write and read code by sharing method names - This option is not applicable to inheritance. While inheritance does allow sharing method names between parent and child classes, it is not the primary purpose of inheritance. Sharing method names can be achieved through other mechanisms as well, such as interfaces or implementing common interfaces.
Option C) Hide and protect data from external code - This option is not applicable to inheritance. Hiding and protecting data is achieved through encapsulation, which is a different concept in OOP. Inheritance focuses on code reuse and the relationship between classes, rather than data hiding.
Option D) Both a and b - This option is incorrect because option B is not a valid reason for inheritance.
Option E) All of the above - This option is incorrect because option C is not a valid reason for inheritance.
The correct answer is option A. Inheritance makes it easier to reuse and modify existing modules of code by inheriting properties and methods from a parent class.