In my experience as a hiker, the moment a black bear becomes aware of your existence, they haul ass in the opposite direction.
Unless they're absolutely starving, it's really unlikely that one will attack you. Even with cubs they're far more likely to stick them in a tree and run away than to attack.