If two objects are moving along the same line but at different speeds, then they will have a relative velocity relative to one another. We can find this by simple addition or subtraction.
The relative speed of car A relative to car B above is 40-30=+10 m/s and the relative speed of car B relative to car A is 30-40=-10 m/s.
In carrying out these calculations we are transforming velocities between three frames of reference.
In a frame of reference stationary relative to the road,
any point on the road has a speed of 0 m/s
car A has a speed of 40 m/s
car B has a speed of 30 m/s
In a frame of reference stationary relative to car A,
any point on the road has a speed of -30 m/s
car A has a speed of 0 m/s
car B has a speed of 10 m/s.
In a frame of reference stationary relative to car B,
any point on the road has a speed of -40 m/s
car A has a speed of -10 m/s
car B has a speed of 0 m/s.
Note that any frame of reference is stationary relative to itself.