Hint: Define spring constant. Obtain the expression for the restoring force of a spring. This is given by Hooke's law. Restoring force of the spring is directly proportional to the displacement of the spring. Equate this force to the weight of the block of mass M. Then we can obtain the solution to this question.
Complete answer:
The spring constant of the spring is $k$. The spring is attached to the ceiling and a block of mass $M$ is attached to the spring. Due to the weight of the block the spring will stretch. Let the spring be stretched by a distance $x$ from its equilibrium position due to the weight attached to its end. The weight of the block is $Mg$.
Now the spring will be stretched with the force $Mg$, because there is no other external force acting on the spring. The spring will try to retain its original form by compressing it to the equilibrium position.The restoring force on the spring will be,
$F=kx$
Where, $k$ is the spring constant of the spring.
And the energy energy stored in the string is,
$U= \dfrac{1}{2}k{x^2}$
The potential energy stored in the block is,
$P.E. = Mgx$
The energy stored in the spring must be equal to the potential energy of the block.
$\dfrac{1}{2}k{x^2} = Mgx$
$\therefore x = \dfrac{2Mg}{k}$
Therefore, the correct option is (B).
Note: The restoring force on the spring will be directly proportional to the displacement of the spring from equilibrium position.
$F\propto x$
We can equate the equation by introducing the proportionality constant k.
$F=kx$
The spring constant is different for different springs. It is also called the stiffness constant.