I've had a few encounters with black bears in Montana and most recently in Redwood National Park. These bears are not habituated to people so the story will be different if you came across a particularly friendly bear - or one that follows you, as was the case in a recent death. In one case, a group of us came upon a mother with a couple of cubs. They were on the other side of a forest opening so we saw each other at quite a distance. Rather than running, which seems to be more common, mom chased the cubs up a tree then walked around underneath them.
We watched for awhile then moved on. I would NOT recommend trying to see how close you can get. There is a fine line that if you cross it, the bear may run you down. In the Redwoods, a couple hiking ahead of us returned after seeing some bears. They told us the bears ran rather than holding their ground. With that info, we proceeded. We found that the bears had been eating blackberries.
On our return, we came across a bear that was well ahead of us and just off the trail in a blackberry bush. It was getting dark and the bear didn't see us. We had to go past the bear or a detour would have been in order. Knowing that we were at the same elevation and the bear was a good distance away, I just yelled. As is typical, the bear took off down hill as fast as it could. Don't scare a bear when you are downhill from it. It might, unintentionally, come right toward you. In general, black bears are looking for food. They might think your food is their food, but they don't normally think of you as food. Grizzly bears are an entirely different story. Outside of Canada and Alaska, you aren't likely to ever see a grizzly. They are around, but they make themselves very scarce. In Glacier National Park where you might see one, it is highly recommended that you wear "bear bells". These are just small bells that make noise as you hike. Grizzlies hear them and get away before you come upon them. Still, grizzlies are unpredictable - there are no guarantees.