In java, if we type an argument-ed constructor for a class, we cannot call it’s default parameter less constructor. I know that is because of the compiler not providing the default parameter less constructor if we type any argument-ed constructor. But my question is what is the reason to design it like this?
Share
If you provide a constructor with arguments it’s assumed the object will be created with valid state.
If a no-arg constructor was exposed by default (and the class’s creator didn’t take defensive action), it would be possible for someone to inadvertently create an invalid object–an object without enough information to be correct.
By forcing us to provide a no-arg constructor, Java forces us to explicitly communicate that it’s okay to create an object without those initial values/state.
Nutshell: Java is attempting to save us from ourselves, because we are sloppy and forgetful.