Fish do not have ear openings, but they do each have an inner ear that allows them to hear. Sound transmits directly to water, and that allows fish to hear if people or animals are near them outside of the water.
How well a fish can hear depends on the type of fish. The distance between the swim bladder and the inner ear can also affect fish hearing. Species of fish that don't have a swim bladder, have a small swim bladder or have a swim bladder far away from the inner ear are not able to hear as well as other fish.