Pretty easy question, but anyway: is there any reason to override default constructor like this:
public SomeObject(){
}
It is public. It is does not have any logic. So, is there necessary? I didn’t see the whole picture?
Appreciate all your help.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
One reason to define an empty no-arg constructor is if there is also a non-default constructor and the no-arg constructor is still desired to be accessible (public or protected).
This is because any [other] constructor definition will prevent the automatic addition of the default no-arg constructor:
(See the next bit in that link as well, where it talks about the default super constructor that will be called.)
Even if the no-arg constructor is never used manually, it can be important for other things, e.g. Serializable: