First rule of hiking: Keep your dog under control at all times.*
Second rule of hiking: You are in the cows' territory - treat them with respect.
In general, I give cows a wide berth - they deserve a quiet afternoon of grass munching as much as I deserve a quiet afternoon of hiking with my mutts. It is up to me to ensure that my dogs do not disturb the cows.
Generally, cows are pretty docile, and most who graze in public hiking areas are accustomed to humans and dogs. When I must cross an open field with cows grazing, I skirt around the edges, keeping my dogs to the outside - I am always between the cows and the dogs. Walk calmly and confidently, and don't make too much noise. If I come into a clearing, find a cow right in my path and have no option to go around, I put the dogs into a sit or down behind me and just stand there calmly - the cow generally wanders off. I've only once had a cow seriously interested in the dogs - probably a calf, quite playful. She persisted for a while, but as my dogs and I stayed calm and non-reactive, eventually she got bored following us and wandered off.
The important thing is that my dogs know I will deal with the situation, they do not have to get excited. Towards that end we do a lot of 'cow practice' on our daily walks. The cows around our house are behind fences, but we practice the drill nonetheless. The dogs know that the sight of a cow means change to the outside, wait for instructions.
If in an open field with mother cows and young calves, I turn and go another way even if it means a longer hike. I do not mess with the mothering instinct - and never get between a mother cow and her calf. I've never come across a bull in 12 years of hiking here - but I'd give one of those a very wide berth indeed.
*For some dogs/owners, 'under control' means on lead. Mine have almost solid recall, but almost is not good enough in an emergency - so they stay on lead when out hiking. If your dog's recall is 100% absolutely rock-solid and distraction proof, then off lead (unless otherwise signed, in forests during the spring or during hunting season, or in Kt SZ) is allowed, indeed encouraged - but your dog must be in sight and under voice control at all times. Oh, and do be sure you pick up after your dog, especially when in a cow pasture.
This applies to encounters with not only cows, but also other hikers, joggers, cyclists and other dogs. Be aware that we all share the hiking trails; respect others, make way for them when possible. (My dogs are trained to step off the path and sit nicely when other hikers pass - mostly a PR exercise in an increasingly dog-intolerant world.) Keep your dogs under control at all times, do not allow them to approach anyone or any critter without first asking permission.
Happy hiking!