If you acknowledge the number of males to females in the ratio as 'parts' or 'items', then there are 6 parts in 42 students. Therefore, 1 part = 42/6 = 7 students.
Therefore, put this into the ratio, and you get 7×2 : 7×4 = 14 : 28
Therefore, there are 28 females in the class.