$$\textbf{Step -1:
Form the required equations.}$$
$$\text{Let the number of girls in class
}A\text{ be }x.$$
$$\text{Let the number of girls in
class }B\text{ be }y.$$
$$\text{Let the number of boys in
class }A\text{ be }35-x.$$
$$\text{Let the number of boys in
class }B\text{ be }35-y.$$
$$\text{If seven girls are shifted
from class }A\text{ to }B,$$
$$\text{Number of girls in class
}A\text{ would become }x-7.$$
$$\text{Number of girls in class
}B\text{ would become }y+7.$$
$$\text{But according to the
question,}$$
$$y=x-7$$
$$\Rightarrow x-y=7\ldots(i)$$
$$\text{If four girls are shifted
from class }B\text{ to }A,$$
$$\text{Number of girls in class
}A\text{ would become }x+4.$$
$$\text{Number of girls in class }B\text{
would become }y-4.$$
$$\text{But according to the
question,}$$
$$x+4=2y$$
$$\Rightarrow x-2y=-4\ldots(ii)$$
$$\textbf{Step
-2: Solve the above formed two equations simultaneously.}$$
$$\text{On subtracting equation
}(ii)\text{ from }(i),\text{ we get}$$
$$-y+2y=7+4$$
$$\Rightarrow y=11$$
$$\text{On putting the value of
}y\text{ in equation }(i),\text{ we get}$$
$$x-11=7$$
$$\Rightarrow x=18$$
$$\textbf{Step -3:
Find the number of boys in class A and B.}$$
$$\text{Number of boys in class
}A=35-18$$
$$=17$$
$$\text{Number of boys in class
}B=35-11$$
$$=24$$
$$\textbf{Therefore, option D is correct.}$$