Syntaxįollowing is the syntax of a constructor − However, once you define your own constructor, the default constructor is no longer used. Typically, you will use a constructor to give initial values to the instance variables defined by the class, or to perform any other start-up procedures required to create a fully formed object.Īll classes have constructors, whether you define one or not, because Java automatically provides a default constructor that initializes all member variables to zero. However, constructors have no explicit return type. It has the same name as its class and is syntactically similar to a method. A constructor initializes an object when it is created.