The correct response is:
when there is a chemical reaction between metals and nonmetals.
This is because certain chemical reactions, particularly those involving metals and nonmetals, can create a flow of electrons, which can be harnessed to produce electrical energy, as seen in batteries and galvanic cells.