Sobes.tech
Junior — Middle

Explain the fundamental purpose of using inheritance in object-oriented programming.

sobes.tech AI

Answer from AI

The fundamental goal of inheritance in object-oriented programming is code reuse and the creation of class hierarchies, where child classes inherit properties and methods from parent classes. This allows modeling 'is-a' relationships, simplifies extending functionality without duplicating code, and helps organize the program into a logical structure.

For example, if there is a base class Animal, then classes Dog and Cat can inherit common methods and attributes from it, while adding their specific features.