Answer: The correct answer is-
B. by mutating their DNA in response to environmental conditions to gain beneficial traits.
Antibiotic resistance in bacteria means the bacteria is not susceptible to the antibiotic that is the effectiveness of antibiotic against the bacteria is eliminated or reduced.
It occurs when bacteria undergoes mutation that is alteration in the genetic material ( for instance, in one mechanism of resistance, mutation changes the protein that was earlier target for the antibiotic).
Therefore, by mutating the DNA in response to environmental condition ( such as exposure to antibiotic in this condition), bacteria gains beneficial characters and become resistant.
Thus, option B) is the right answer.