Trained, but not intentionally. One day, someone waved at a bear, the bear made a sort of waving motion, and received a thrown treat. The next time someone waved, he waved back, and the person fed them. Thus, waving became associated with rewards.