C++ Inheritance and Access Specifier Explained

To put it in the simplest of terms, an inheritance is a process in which one entity takes another entity’s characteristics and makes it it’s own. Let’s take ponytail hairstyles as an example. Ponytail, by itself, is an entity because it is a predefined style of hair. In addition, it also has its own unique visual characteristics. In most cases, it is represented in the form of a single strand of hair on the back of the head by the hindbrain area. However, it does not mean that all ponytails have to follow this one strand of hair doctrine. There could very well be a wide array of variations of this same hairstyle, and this, in a nutshell, of varying styles is the fundamental concept of inheritance. It is still categorized as a ponytail because it still has that unique strand of hair characteristics from the original entity. The catch, however, is that on top of that one original strand of hair, one could elect to get two strands instead, and it doesn’t necessarily have to be behind the head; it could be two strands on the sides of the head. Nevertheless, it still took the original strand, which uniquely identifies it as a ponytail, and expanded more unique characteristics to it. Now that we have the concept of inheritance squared away. Let’s expand into public and private access specifiers, and that is, public, private, and protected access levels dictates which class members are inheritable. In this case, public traits are inheritable while private traits are not. In other words, from a genetic perspective, it is basically the difference between dominant and recessive genes. In short, if certain characteristics belong only to that one particular variation of “Ponytail,” you would want to keep it private. If you don’t want other people to make a ponytail design based on your original unique design, get it copyrighted, or in this case, leave it private. Otherwise, make it public and share it with us! 😂

Leave a comment