Do I really need to define default constructor in java?

Ayush Goyal picture Ayush Goyal · Sep 4, 2010 · Viewed 44.3k times · Source

It works fine when constructors are not defined, but gives errors if I define a parameterized constructor and not a default one and not passing any values while creating an object. I thought constructors are predefined.

Why do I need to define a default constructor if I've defined a parameterized constructor? Ain't default constructor predefined?

Answer

Justin Ardini picture Justin Ardini · Sep 4, 2010

A default (no-argument) constructor is automatically created only when you do not define any constructor yourself.

If you need two constructors, one with arguments and one without, you need to manually define both.