It was revealed in the fifth book, *Harry Potter and the Order of the Phoenix*, when she learned to produce a Patronus to fight off Dementors.