When two bodies stick together after collision, then the collision is said to be perfectly inelastic.
In inelastic collision most of the kinetic energy is lost in other forms (specially as heat). Thus, in inelastic collision the kinetic energy is not conserved but total energy and momentum are conserved.
From law of conservation of momentum
$m_{1} \,u_{1}+m_{2}\, u_{2}=\left(m_{1}+m_{2}\right) v$
$40 \times 4+60 \times 2=(40+60) v$
$\Rightarrow v=\frac{280}{100}=2.8 \,m / s$
Decrease in kinetic energy
$=\frac{1}{2} m_{1}\, v_{1}^{2}+\frac{1}{2} m_{2}\, v_{2}^{2}-\frac{1}{2}\left(m_{1}+m_{2}\right) v^{2} $
$=\frac{1}{2} \times 40 \times(4)^{2}+\frac{1}{2} \times 60 \times(2)^{2}-\frac{1}{2}(40+60)(2.8)^{2}$
$=320+120-100 \times 3.92$
$=48 \,J .$
Note: It is not necessary that in inelastic collision, there is always a loss of kinetic energy. If in collision, the potential energy of a body is released then the kinetic energy would increase.