Tech Mahindra interview question

What is the necessity of having a constructor in Java code?