Witscale Test Center

3.6 Code blocks and modifiers


3.6 Code blocks and modifiers

A code block is a sequence of statements enclosed by curly braces. Blocks can be present inside a method body or they may be freely-floating inside a class body. You cannot explicitly call the code blocks. For instance, the code blocks within a method body are executed when the method is called.

The execution of blocks takes place in the order of their appearance in the code. Though blocks can be declared within a class’s body, they are not considered as class’s members. Most modifiers (including access modifiers) are applicable only to class members. Note that static and synchronized are the only two modifiers that are applicable to the blocks.