The momentum of the system, consisting of the boy and the cart, must be conserved in the absence of the net external force.
Initial momentum of the system,
pi = m1u1 + m2u2
pi = 40 x 5 + 20 x 2 = 240 kg m/s
Finally, both the boy and the cart are moving together with the same velocity.
Hence, the final momentum of the system, pf = (40 + 20) x v = 60v
By the conservation of momentum,
pi = pf
⇒ 240 = 60v
⇒ v = 24060
v = 4 m/s