They are inherited. Ethologists call them FIXED ACTION PATTERNS (FAP's). What are some other examples? (hunting, courting?)
Most FAP's are blocked and seem to need an IRM (= INNATE RELEASING MECHANISM) to set them off. IRM's, in turn, require an outside RELEASER for each specific behavior pattern. In a famous example: When Herring Gulls feed their chicks, the chick pecks at the parent's bill. The parent, stimulated by this pecking, regurgitates a mass of food. So an ethologist offered Herring Gull chicks all sorts of parent head models. Regardless of shape of the head, the chick always pecked at those bills with red on them. Apparently the red on the parent's bill releases the IRM for pecking for the young, which, in turn, released, quite literally, regurgitating in the adult.
Of course many other behaviors are releasers: a female turkey will kill her own chicks if she can't hear them. European Robins have red breasts--orange in immature--males will attack red color in general, despite shape of the head (like a red mail truck). A flicker's mustache is probably a good example of a releaser. Many gulls with black-heades don't face each other since the sight of a black head releases aggression.
You can also have SUPER RELEASERS: European Oystercatchers prefer huge artificial eggs to their own!
--before moving onto learning, I should mention two or three other interesting types of behavior--