Flies can stick to walls due to tiny hairs on their feet called setae. These setae have small pads at their tips that secrete a sticky substance, allowing flies to adhere to surfaces. The setae also have a unique structure that lets them be pulled in and out, increasing grip. Additionally, the hairs are covered in tiny hooks that help anchor the fly to the surface.