Originally posted by Satya Maheshwari:
One way of looking constructor is to consider it as a suitable place where you can write code which needs to be executed whenever an object of that class is intantiated. The code should usually be doing the initialization stuff for that object.
Be bold, Maheshwari!
The constructor is where you initialise the object. Not "should" or "usually." For the beginner, let's think of that as "always." [There
are other ways to initialise objects, like factory methods, but let's look on them as more advanced than we need here.]
Every field has a default value when it is declared, but that is usually not suitable for real-life use, so you initialise them to "real" values in the constructor.
Nitin: who is teaching you programming? Have you got a course of any sort?