Part I
-
Why do we need inheritance in C++?
To create new objects by acquiring the attributes and behavior of other objects and then expand them and build more complex classes. -
Give a simple example of objects in the real world that could be modelled in C++ using inheritance.
There are many. For example, a vehicle is a car and a car is also a vehicle, and a motorbike is a vehicle and a vehicle is also a motorbike. But a motorbike is not a car and a car is not a motorbike. These relationships are important for a program to distinguish between and also make code reusable.
Part II
-
What is a superclass and what is a subclass?
a subclass is the class inheriting from a superclass. -
How would you write a public inheritance in C++?
Motorbike is a Vehicle
class Motorbike : public Vehicle {…};
-
In what ways can a subclass extend the functionality of a superclass?
A subclass can extend the implementation of a superclass with additional fields and functions, to create a more specific object.