Needless to say, if a species is hermaphroditic, this makes it considerably easier for individuals to find mates, since
any member of the same species is a potential mate. Another way in which animals can cope with a lack of suitable mating partners is by changing sex. In many fish species, for instance, individuals can change from males that produce spermatozoa to females that produce ova or
vice versa, depending upon which sex is rarer and more in demand by potential mates. In fact, among coral-reef fish species, those that
cannot change sex are the exception – most species can change sex in one or both directions.

The reef fish Labroides dimidiatus
(Phylum Chordata). In this species, males are dominant.
If a dominant male dies, a female can change sex and take his place.