How the body fights infection
Skin, mucus and stomach acid block whatever arrives, while antibodies and memory cells target one specific pathogen.
A worked example
A measles vaccine presents the antigen without causing the disease, so memory cells are already in place if the real virus arrives years later.
The mistake people actually make
Antibiotics kill bacteria and do nothing to viruses, so they cannot treat a cold. Stopping a course early leaves the hardiest bacteria alive to multiply.