It is because of a principle called Buoyancy. Buoyancy is the upward force exerted by a fluid that opposes the weight of an immersed object. When a boat or ship is designed correctly, it displaces enough water to generate an upward force equal to or greater than its weight, keeping it afloat. This is why they float on water instead of sinking. It's like a balancing act between the weight of the ship and the water it displaces.