Constructor is the method of the class that has the same name as that of the class. It is specially used to initialize the object. There are two types of the constructor:

  • Default Constructor: In the case of the default constructor, no arguments are passed in the constructor definition. If we don't declare the default constructor, it will be created automatically to initialize the instance variables with the default values.
  • Parameterized Constructor: In parameterized constructor, you can pass any number of arguments in the constructor definition. The arguments are defined with arguments. You can initialize the instance variables along with provided values.