13
Inheritance
Inheritance is a fundamental concept in object-oriented programming (OOP) that allows a child class to inherit properties and behaviors from another class (parent or base class). Inheritance enables code reuse, promotes a hierarchical organization of classes, and facilitates the creation of a more organized and maintainable code base.
Inheritance follows the is-a relationship, meaning a child class is a specialized version of the parent class. It can access all the parent class’s public and protected members (variables and methods) but not private ones. The child class can also override the methods of the parent class to provide its specific implementation while keeping the rest of the inherited behaviors intact.
In this chapter, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access