So for $\ce{SO2}$, here's the solution when finding for the oxidation number of sulfur.
$$x + 2(-2) = 0 \\ x - 4 = 0 \\ x = +4$$
$x$ here would be the oxidation number of sulfur, so the compound would now be $\overset{+4}{\ce S} \overset{-2}{\ce{O2}}$.
Now if I tried using oxygen as the $x$ it would become: $$1(-2) + 2x = 0 \\ -2 + 2x = 0 \\ 2x = 2 \\ \frac{2x}{2} = \frac 22 \\ x=1$$
So, in this case the compound would actually be $\overset{-2}{\ce S} \overset{+1}{\ce{O2}}$.
I'm pretty confused about this since we just got into this today and haven't checked many examples. There is probably something I'm missing in the solution or a rule. Can someone explain to me the correct one? And also can't sulfur's and oxygen's oxidation number both be -2 as they're in group VI(A)?