How did adding beehives around the corn crops stop the elephants from eating and trampling the corn?

Adding beehives around the corn crops deterred elephants from entering the area because they are sensitive to the buzzing of bees and fear getting stung. The elephants would avoid the cornfields to prevent encountering the bees which prevented them from eating and trampling the crops.