When two metals touch each other and water is present, electrolysis occurs. One well known example is the reaction between zinc (Zn) and iron (Fe). Zn atoms ionize as it is more electropositive and is oxidized and corrodes.
(aq) +2e (oxidation)
Sacrificial metals are widely used to prevent other metals from rusting, for example food cans. Most of the food can is coated with a layer of metal that is more electropositive than the metal (mostly iron) inside the food can, preventing the iron contaminating the food with Fe2+
ions. It can also be attached to the hull of a ship to prevent it from rusting and breaking down.