Let x be the total weight of all the students.
It is given that mean weight of 60 students is 40 kg.
So,
x60=40
x=2400
Let y be the number of boys in the class.
The mean weight of boys is given as 50.
The total weight of boys is 50y.
The mean weight of girls is given as 30. The total weight of girls will be 30(60−y).
So,
2400=50y+30(60−y)
2400=50y+1800−30y
600=20y
y=30
Then, 60−y=60−30=30
Therefore, the number of boys is 30 and the number of girls is 30.