-
Book Overview & Buying
-
Table Of Contents
Expert C++ - Second Edition
By :
Inheritance and polymorphism are two of the four main principles that OOP has. The four principles are as follows:
We have already talked about the first two principles, and now it is time to dive deeper into the final two – inheritance and polymorphism.
Classes can be reused, thanks to the programming notion of inheritance. Different programming languages offer various inheritance implementations, but the underlying principle is always the same – the class relationship should answer the is-a question. For instance, Car is Vehicle; hence, we can inherit Car from Vehicle:
class Vehicle {public:
void move();
};
class Car : public Vehicle {
public:
Car();
// ...
};
Car now has the move() member function derived from Vehicle. The relationship between generalization and specialization...