What do you mean by Constructor?

Love and Share

Answer: Constructors are special class functions in object-oriented programming which performs initialization of every object.   A constructor is an instance method that usually has the same name as the class, and can be used to set the values of the members of an object, either to default or to user-defined values. onstructors iitialize values to object members after storage is allocated to the object.

Constructor gets invoked when a new object is created. Every class has a constructor. If we do not explicitly write a constructor for a class the java compiler builds a default constructor for that class.

Love and Share

Leave a Reply

Your email address will not be published. Required fields are marked *