What are Blocks of code in Java?

In Java, you can group two or more statements in a block of code. Thus, a block of a code is a logical unit which could be used as a whole, anytime in the program. Blocks of code are created by enclosing any statements in curly braces.

For Example:

if(a > b ) { // block begins

a = a+1;

b= = b-1;

} // block ends

Leave a Reply