In
object O {
// construction code and member initialization
}
construct, when is this code going to be run?
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.
The code will be called when
Ois accessed the first time (some method or some property). For example the following programwill yield
It’s not enough to simply define
O. Also it won’t work to to callClass.forName("O")since the compiled object’s name isO$, so callingClass.forName("O$")will do.