1. Why do we need inheritance in C++?
Inheritance let’s you build complex classes, which builds an “is-a” relationship between two objects. It involves creating new objects by directly acquiring the attributes and behaviors of other objects and then extending or specializing them. This avoids duplication and improves your code.
2. Give a simple example of objects in the real world that could be modeled in C++ using inheritance.
Furniture<Table<coffee table and also Furniture<closets<dressings
3. What is a superclass and what is a subclass?
A superclass is a class being inherited, so in my example, it’s furniture, the subclass is then Table. Table is then the superclass to the coffee table sub class. Subclasses inherit the functions and properties of parent classes.
4. How would you write a public inheritance in C++?
class [INSERT NAME OF THE SUBCLASS YOU ARE CREATING] : public [INSERT NAME OF PARENT CLASS]
{
...
};
5. In what ways can a subclass extend the functionality of a superclass?
They do so by either adding variables or members, on top of the inheritance from the superclass.