Block

Definition

A block is any piece of code surrounded by {}s. When a block is exited, any variables declared within the block are recycled (See Variable Scope). Blocks can hold methods, loops, separate blocks or otherwise. The following code contains four blocks:

public class ClassHere {   //first block
  public static void main(String[] args) {   //second block
    int a = 0;
    for(int i = 0; i < 10; i++) {   //third block
      a = change(a);
    }
    System.out.print(a);
  }
  public static int change(int a) {   //fourth block
    a += 2;
    return a;
  }
}

Block(s) Visual

55260%2060%20Blocks.jpg
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License