A ship made of iron and steel is a hollow object which contains a lot of air in it. Due to the presence of a lot of air in it, the average density of the ship becomes less than the density of water. Hence a ship floats in water.
On the other hand, a piece of iron is denser than water, so it sinks in water.