package test;
public class Demo1 {
/*
* 定义在语句块内部的是局部变量*/
static {
}
/*局部变量时定义在方法中或语句块中*/
public static void main(String[] args) {
//局部变量必须要在使用前给值
int a = 10;
System.out.println(a);
}
/*方法的参数也是局部的变量,使用的范围在这个方法的大括号内。*/
public static int add(int a, int b) {
return a+b;
}
public static void test() {
//for循环也是一个语句块,i的使用范围在for的大括号内
for(int i = 0; i < 10; i++) {
}
}
public static void test1() {
//普通语句块,基本不用
{
}
}
}