BB = 50
SOC = 60
HOC = 40
sum = 150
SOC + HOC = 12
BB + SOC = 30
BB + HOC = 20
BB + SOC + HOC = 10
first, these 10 we need to deduct twice from the total, as they were counted 3 times :
150 - 2×10 = 130
then the 12 of SOC + HOC minus the 10 BB + SOC + HOC = 2 were double counted and need to be removed once :
130 - 2 = 128
then the 30 of BB + SOC minus the 10 BB + SOC + HOC = 20 were double counted and need to be removed once :
128 - 20 = 108
then the 20 of BB + HOC minus the 10 BB + SOC + HOC = 10 were double counted and need to be removed once :
108 - 10 = 98
so, there were 98 students in the class.
FYI
so, there were
50 - (20 + 10) - 10 = 10 students playing only basketball.
60 - (2 + 20) - 10 = 28 students playing only soccer.
40 - (2 + 10) - 10 = 18 students playing only hockey.
in sum
10+28+18+2+20+10+10 = 98