We apply paint on objects made of iron not only to make them look attractive, but also to prevent them from rusting.
Now what is rusting? When iron is exposed to moist for a long time it acquires a coating of brown hard layer on it called rust. Which is developed because iron easily react with water and air which results in rusting of any object made of iron. This whole process of rusting of iron is called corrosion. It happens not only on iron but on many other objects which form a hard layer on object but of different colour. There is a condition that iron will only rust when it is in contact with water and air for long time without any protection layer on it.
The rusting of Iron can be prevented by painting, oiling, greasing, etc. These things create a protection layer on iron, which prevent iron to come in contact with air and water.
Example- We all have seen iron nails in our household which are used to hang things. When they are new they appear silver or have shiny luster on them. But after 2 or 3 months if you notice the same nail it will appear to have a brown hard layer coating on it. That is rust.
On the other hand if you see the cycle that we all had as kids or have. Some part of it is made of iron which is painted and if paint is removed we can clearly see the iron. We also take our cycles for oiling monthly so that the chains in cycle won’t get stuck or stop working, start creating weird crackle noise if they are not oiled or greased monthly.