Let the speeds of the cars be \( x \) km/h and \( y \) km/h.
Case 1: Moving in the same direction.
When the cars move in the same direction, the relative speed is \( |x - y| \) km/h, and they meet after 8 hours. Therefore:
\[
|x - y| \times 8 = 120 \quad \Rightarrow \quad |x - y| = \frac{120}{8} = 15.
\]
Case 2: Moving in opposite directions.
When the cars move in opposite directions, their relative speed is \( x + y \) km/h, and they meet after 2 hours 40 minutes, or \( \frac{8}{3} \) hours. Therefore:
\[
(x + y) \times \frac{8}{3} = 120 \quad \Rightarrow \quad x + y = \frac{120 \times 3}{8} = 45.
\]
Now, solving the system of equations:
\[
|x - y| = 15 \quad \text{and} \quad x + y = 45.
\]
Adding these two equations:
\[
(x + y) + (x - y) = 45 + 15 \quad \Rightarrow \quad 2x = 60 \quad \Rightarrow \quad x = 30.
\]
Substituting \( x = 30 \) into \( x + y = 45 \):
\[
30 + y = 45 \quad \Rightarrow \quad y = 15.
\]
Thus, the speeds of the cars are 30 km/h and 15 km/h.