Inheritance
Learn about the concept of inheritance in object-oriented programming.
We'll cover the following...
Inheritance
As we can see, the power of object-oriented programming is that objects are self-contained entities that control their data. But object-oriented programming has another powerful feature that will let us reuse code, and that is the concept of inheritance.
The is-a relation
If someone asked you if they could borrow your phone to make a call, it would not matter if you gave them your smartphone, an old mobile phone from 2005, or even access to a landline telephone. They all share some of the same features, with one of them being the ability to make phone calls. We could define this with a chain of statements, as follows:
- A smartphone is a mobile phone.
- A mobile phone is a telephone.
- A telephone can make phone calls.
- A smartphone can, therefore, make phone calls.
We could say that we have several levels of abstraction where we have a relationship between the levels. This is what we ...