How do dogs learn protective instincts?

How do dogs learn protective instincts?