Why are nucleic acids considered molecules of heredity?

because Deoxy Nucleic Acid and Ribo Nucleic Acid are made of Nucleic acid (DNA and RNA)