x=number of boys.
y=number of girls.
We can suggest this system of equations:
x+y=511
y=x+165
We can solve this system by substitution method.
x+(x+165)=511
2x=511-165
2x=346
x=346/2
x=173
y=x+165
y=173+165
y=338
Answer: there are 173 boys in the class.