Dogs not only have selective hearing, they also have selective intelligence. When something interests them, or immediately benefits them in some way, they can be pretty darn smart about figuring things out. Like how to get food, get out of the yard, etc.