Lesson 13 - Inheritance in C++
In the previous lesson, Assignment operator, we defined the basic methods that a usual
class should have. In today's tutorial, we're going to expand our knowledge of
object-oriented programming. In the introduction of this course, we mentioned
that the OOP is based on three fundamental concepts:
encapsulation, inheritance and
polymorphism. We're already familiar with the encapsulation and
have used the
private access modifier. Today, we're going to be
taking a look at the inheritance.
Inheritance is one of the basic features of OOP and is used to create new data structures based on old ones. Let's look at a simple example:
Imagine that we were hired to create a database that will keep track of
animals at a zoo There will
be two types of users in our system: users and administrators. Users will be
common zookeepers who will be able to edit information about the animals, e.g.
their weight or wingspan. The administrator will be able to modify animal data
as well and add or delete animals from the database. Administrators will have an
extra field, a phone number so they can be contacted in case of system failure.
It'd be pointless and confusing to fully define both classes since they have
many fields and methods in common. Both the user and the administrator will have
names, ages and be able to log in and log out. Let's define only the
...End of the preview...
You've come here and that's great! We believe that the first lessons showed you something new and useful
Do you want to continue the course? Go to the premium section.
- Unlimited and permanent access to individual lessons.
- High quality IT knowledge.
- Skills to help you get your dream and well-paid job.
Requested article covers this content:
In this tutorial, we'll explain the fundamentals of object inheritance in C++. We'll learn to reuse code and use inheritance correctly.
You gain points by supporting our network. This is done by sending a helpful amount of money to support the site, or by creating content for the network.