Hello people. I need an explanation about inheritance I got a little confused in class:
This is the modelling problem:
There are two objects: doctors and patients. They are expected to have only the following attributes:
Doctors have: name, age, id, and salary
Patients have: name, age, id, and disease type
Since three of the 4 attributes are repeated, we were told to use inheritance. So we created a People class containing name, age and id as attributes and one method for setting those variables to a given value.
Here comes the problem:
In class we instantiated the parent class together with the other 2 children. Then, the teacher used the set method OF THE PARENT CLASS to take care of the 3 common variables and then used the children's methods to set the remaining variables that were still not set. Finally, he accessed the age, id and name variables of the parent class, and the salary and disease type variables of the children classes
Is this truly inheritance? Can't we use only the children, since they will also have the setter method created in the parent along with the parents three attributes?
Let me know if you don't undertand my question. I admit it's a little confusing