4. Let the quadratic function $y_{1}=a\left(x-x_{1}\right)\left(x-x_{2}\right)$ (constants $\left.a \neq 0, x_{1} \neq x_{2}\right)$ intersect with the linear function $y_{2}=d x+e$ (constants $d \neq 0, e$ to be determined) at the point $\left(x_{1}, 0\right)$. If the graph of the function $y=y_{1}+y_{2}$ intersects the $x$-axis at only one point, then the value of $x_{2}-x_{1}$ is ( ).
(A) $-\frac{d}{a}$
(B) $-\frac{e}{a}$
(C) $\pm \frac{d}{a}$
(D) $\frac{d}{a}$
4. D.

Given that the graph of the linear function $y_{2}=d x+e(d \neq 0)$ passes through the point $\left(x_{1}, 0\right)$, we have
$$
\begin{array}{l}
y_{2}=d\left(x-x_{1}\right), \\
y=y_{1}+y_{2}=\left(x-x_{1}\right)\left(a\left(x-x_{2}\right)+d\right) .
\end{array}
$$

Since the graph of the function $y=y_{1}+y_{2}$ intersects the $x$-axis at only one point, $y=y_{1}+y_{2}$ is a quadratic function, and its vertex lies on the $x$-axis, i.e.,
$$
\begin{array}{l}
y=y_{1}+y_{2}=a\left(x-x_{1}\right)^{2} \\
\Rightarrow a\left(x-x_{2}\right)+d=a\left(x-x_{1}\right) .
\end{array}
$$

Let $x=x_{1}$, we get $a\left(x_{2}-x_{1}\right)=d$.
Therefore, $x_{2}-x_{1}=\frac{d}{a}$.