Answer:
This happens because of our immune system. Our immune system keep record of every attacking microbe. It contains two type of while blood cells firstly is T cell that respond quickly to the attacking microbe. While secondly B cells that recognize those specific cells and fights them off. In addition to that B cells clones itself as memory cells for that disease and will remains in your body for years