If this was the case and the cattle class would cause airlines to lose money you would definitely see airlines flying smaller planes just for the first class.
Most likely what happens is that cattle class pays for the plane to fly, and airlines make more from first class.
See https://en.wikipedia.org/wiki/Business_class_airline for a small number of examples