Pain sensation produced in one part of the body is felt in another part of the body away from the site of origin.
The deep pain and some other visceral pain are referred to other areas
Cardiac pain is felt in the left arm, left shoulder, lower jaw or left upper chest. It may be felt as an esophageal pain, mimicking esophagitis.
Pain produced in the diaphragm by blood or exudate under the diaphragm may be felt in the shoulder.
Pain of the testis may be felt in the epigastrium
Pain produced by a urinary stone in the ureter may be felt in the loin, testis or upper part of thigh
The pain of appendix may be felt in the umbiilical region instead of in the right iliac fossa.
Probably the reason for the referred pain is the fact that the part where the pain is originating and the part that feels the pain are supplied by nerves from the the same segment of the spinal cord :
Diaphragm and shoulder are supplied by C4 segment of the spinal cord.
Testis and the epigastrium are supplied by the same segments of the spinal cord. (Remember that the testis develops in the epigastric region and later descends into the scrotum bringing the nerve supply and blood supply along with it)
Two popular theories of mechanism of referred pain are