0
Inheritance is-a and has-a relationship
If a define base class vehicle and inherit new class car from base class vehicle, so object of class car is object of vehicle. It implies that car is a vehicle but vehicle is not (only) a car. It means if Vehicle vehicle; Car car; then car = vehicle is a valid statement or assignment, but vehicle = car is not a valid assignment. Am I right? Please give your opinion, class.
1 Antwort
+ 2
'has-a' relationship (if that was the term), is more closely related to composition. Like a vehicle is composed of chassis, engine etc.
'is-a' relationship is like what you wrote, car is-a vehicle, but a vehicle is not limited to, just a car.
But I'm not sure the `=` operator can be used to verify whether or not `car` inherits, or was extended from `vehicle`.