.
From the condition, you have these two equations
     G +  B = 40      (1)
    5G - 4B = 65      (2)
where G is the number of girls and B is the number of boys.
From equation (1), express  B = 40-G and substitute it into equation (2), replacing B there. You will get
    5G - 4*(40-G) = 65
    5G + 4G       = 65 + 160
     9G           = 225
      G           = 225/9 = 25.
ANSWER.  25 girls and the rest, 40-25 = 15 are boys.
Solved.