I think they get worms by eating something. I know for that's true tape worms. You will see shed tape worm segments in their poop. I don't think you'll see the other types (hook, round, whip) live in their poop. Interceptor, for one, prevents hook, whip and round worms in addition to heart worm, but I don't know if it's 100% effective.
Heart worm is spread by mosquitos. As far as I know, any breed (and supposedly cats, too) can get heart worm.