Is a constructor method necessary? Can I have a class without a constructor set up?


#1

Question

Is a constructor method necessary? Can I have a class without a constructor set up?

Answer

Technically, yes – a class can work without a constructor, or with an empty constructor. Constructors have certain purposes and can be very useful. We often use them to initialize properties in an object. We can just as well have a class with an empty constructor but has other methods and properties.