1. Why do we need inheritance in C++
With inheritance we can pass the attributes, properties of one object to another object, which inherit the variables of the predecessor and becomes then a extending or specialist version.
2. Give a simple example of objects in the real world that could be modelled in C++ using inheritance
A mule is the offspring of a male donkey and a female horse. Donkeys and horses are two different species of Equine, with different attributes.
The mule inherit the different qualities of his mother like strength, high etc. and the attributes of his donkey father like fearlessness. This crossover create a new type of Equine which is (was) very useful for transportation or farm work.
Part II
1. What is a superclass and what is a subclass?
A Super class or also called Base Class is a class whose properties are inherited by a sub class.
Sub Class is the class that inherits properties from another class.
2. How would you write a public inheritance in C++?
class PrivatBookLibary:
{
public:
int numberOfBooks{};
string nameOfBook{};
string writerName{};
int pageNumber{};
PrivatBookLibary( int n, string b, string a, int p) {
int numberOfBooks = n ,
string nameOfBook = b ,
string writerName = a,
int pageNumber = p)
}
}
3. In what ways can a subclass extend the functionality of a superclass
The subclass inherit properties and methods from the superclass without redefining the information from parent class.