4. Let $a_{n}=n^{2}+n+2(n=1,2, \cdots)$. Then in the sequence $\left\{a_{n}\right\}$ ).
(A) there are infinitely many prime numbers
(B) there are only finitely many prime numbers
(C) there are infinitely many square numbers
(D) there are only finitely many square numbers
4.D.

Since $a_{n}=n^{2}+n+2=n(n+1)+2$, we have $2 \mid a_{n}$, and $a_{n}>2$. Therefore, $a_{n}$ must be a composite number. This eliminates options (A) and (B). Furthermore, since when $n \geqslant 2$, $n^{2}<n^{2}+n+2<n^{2}+2 n+1=(n+1)^{2}$, it follows that $a_{1}$ is the only perfect square when $n=1$.