Let $X \subseteq \mathbb{A}^{n}$, $Y \subseteq \mathbb{A}^{m}$, where $\mathbb{A}^{n}$ is the affine $n$-space with Zariski topology.
Let $\overline{X}$, $\overline{Y}$ and $\overline{X \times Y}$ be the Zariski closures of $X$, $Y$ and $X \times Y$ (i.e. $\overline{X}$ is the smallest algebraic set in $\mathbb{A}^{n}$ containing $X$, $\overline{Y}$ is the smallest algebraic set in $\mathbb{A}^{m}$ containing $Y$, and $\overline{X \times Y}$ is the smallest algebraic set in $\mathbb{A}^{n+m}$ containing $X \times Y$).
I am asked to show that $$\overline{X \times Y} = \overline{X} \times \overline{Y}$$
I have already shown that $\overline{X} \times \overline{Y}$ is an algebraic set in $\mathbb{A}^{n+m}$, which immediately implies $$\overline{X \times Y} \subseteq \overline{X} \times \overline{Y}$$
However, I don't know how to show that $\overline{X \times Y} \supseteq \overline{X} \times \overline{Y}$. Any help/hints would be appreciated.
To show $\overline{X}\times\overline{Y}\subseteq \overline{X\times Y},$ you can show that every polynomial that vanishes on $X\times Y$ must vanish on $\overline{X}\times\overline{Y}.$
So, consider a polynomial $r(X,Y)$ that vanishes on $X\times Y.$ For each $x\in X$ the polynomial $f(Y)=r(x,Y)$ vanishes on $Y,$ so must vanish on $\overline{Y}.$ So $r$ vanishes on $X\times \overline{Y}.$ For each $y\in \overline{Y},$ the polynomial $f(X)=r(X,y)$ vanishes on $X,$ so must vanish on $\overline{X}.$ So $r$ vanishes on $\overline{X}\times\overline{Y}.$