The relationship between the traffic density \( k \), space-mean speed \( v_s \), and time-mean speed \( v_t \) is given by:
\[
k = \frac{1}{h}
\]
where \( h \) is the headway (time between vehicles) in seconds. We know:
\[
k = 40 \, \text{vehicles/km}, \quad v_t = 40 \, \text{km/h}, \quad v_s = 30 \, \text{km/h}.
\]
The time-mean speed \( v_t \) is related to the space-mean speed \( v_s \) by the equation:
\[
v_t = \frac{v_s}{1 + k \cdot h}
\]
Substitute the known values:
\[
40 = \frac{30}{1 + 40 \cdot h}.
\]
Solving for \( h \):
\[
1 + 40h = \frac{30}{40}, \quad 40h = \frac{30}{40} - 1 = \frac{30 - 40}{40} = \frac{-10}{40}.
\]
Hence,
\[
h = 3 \, \text{seconds}.
\]
Thus, the correct answer is (A).