The sexes often differ in the reproductive trait limiting their fitness, an observation known as Bateman's principle. In many species, females are limited by their ability to produce eggs while males are limited by their ability to compete for and successfully fertilize those eggs. As well as promoting the evolution of sex-specific reproductive strategies, this difference may promote sex differences in other life-history traits due to their correlated effects. Sex differences in disease susceptibility and immune function are common. Two hypotheses based on Bateman's principle have been proposed to explain this pattern: that selection to prolong the period of egg production favors improved immune function in females, or that the expression of secondary sexual characteristics reduces immune function in males. Both hypotheses predict a relatively fixed pattern of reduced male immune function, at least in sexually mature individuals. An alternative hypothesis is that Bateman's principle does not dictate fixed patterns of reproductive investment, but favors phenotypically plastic reproductive strategies with males and females adaptively responding to variation in fitness-limiting resource availability. Under this hypothesis, neither sex is expected to possess intrinsically superior immune function, and immunological sex differences may vary in different environments. We demonstrate that sex-specific responses to experimental manipulation of fitness-limiting resources affects both the magnitude and direction of sex differences in immune function in Drosophila melanogaster. In the absence of sexual interactions and given abundant food, the immune function of adults was maximized in both sexes and there was no sex difference. Manipulation of food availability and sexual activity resulted in female-biased immune suppression when food was limited, and male-biased immune suppression when sexual activity was high and food was abundant. The immunological cost to males of increased sexual activity was found to be due in part to reduced time spent feeding. We suggest that for species similarly limited in their reproduction, phenotypic plasticity will be an important determinant of sex differences in immune function and other life-history traits.