This is an example of; Perspective taking.
Perspective-taking is an active cognitive process of imagining or understanding a situation from a different point of view, such as that of another person. Perspective-taking is important to human development and it is associated with other theories such as the theory of mind and empathy.