F
F
Fedor_Korpatov2021-03-26 12:03:29
Java
Fedor_Korpatov, 2021-03-26 12:03:29

Code blocks - what are they and why are they executed without an explicit command?

Good afternoon.

605da2a5cacd4195866713.jpeg

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

1 answer(s)
D
Denis Zagaevsky, 2021-03-26
@Fedor_Korpatov

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 question

Ask a Question

731 491 924 answers to any question