Can anybody please tell me what the Constructors are used for exactly in Java?
What could be the ideal condition for using the constructors in an application?
Thanks,
david
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.
Constructors are very useful for initializing instance variables. For instance, say you have a
Userclass, and you would like to initialize theuserNameproperty whenever you create a new instance:Note – When you write your own constructor, java doesn’t provide a default constructor