In biology, immunity is the capability of multicellular organisms to resist harmful microorganisms. Immunity involves both specific and nonspecific components. The nonspecific components act as barriers or eliminators of a wide range of pathogens irrespective of their antigenic make-up. Other components of the immune system adapt themselves to each new disease encountered and can generate pathogen-specific immunity.
Immunity is a complex biological system that can recognize and tolerate whatever belongs to the self, and to recognize and reject what is foreign (non-self).
https://en.wikipedia.org/wiki/Immunity_(medical)