We also wonder how they see and talk under water.
Whales just hold their breath like any other mammals and they can it do for up to several minutes.
Sperm whales seem to be the best at that with divings reported to be up to 90 minutes. They see just like any other mammal using their eyes and produce sounds that can be used in many occasions for communication purposes. Sounds are produced internally. They may defend against them. We do know that it may not be infrequent since individuals some species show many times scars from shark bites, particularly the cookie-cutter shark.