DNA from one bacteria can be taken in and used as part of the DNA of another bacterium through a process called horizontal gene transfer.
Transformation - Recipient bacterium takes up extracellular donor DNA
Transduction - Occurs when a bacteriophage containing bacterial DNA infects a recipient bacterium and transfers this bacterial DNA
Conjugation - DNA is then transferred for one bacterium to another through direct contact