When an iron surface is painted, iron does not come in contact with air or moisture. Paint acts as a protective layer and prevents exposure of iron to the atmosphere. Since air and water are necessary for rusting, iron does not get rusted, if painted.