why does a compass needle get deflected when brought near a bar magnet?

Sanjna Taneja's image