What is a Constructor in Java?

A constructor is a special method in Java that creates and initializes an object.

It has the same name as the class.

It does not have a return type.

It is called automatically when you create an object using new.

Why use a Constructor?

To give the object its initial values.

To make sure the object is ready to use right after creation.