Answer the question
In order to leave comments, you need to log in
Code blocks - what are they and why are they executed without an explicit command?
Good afternoon.
I create a class, in it I open a code block static \ non-static.
When an object is created, these blocks are executed, although I did not put them in the constructor and did not execute the methods.
The question is - what is an unmarked block of code (not a method, not a parameter...) and why is it executed without an explicit command?
I want to deal with this issue, what to google?
Answer the question
In order to leave comments, you need to log in
It's not just blocks of code. These are static/non-static initialization blocks. Accordingly, static initialization is performed once at the first call to the class, non-static - each time the class object is created.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question