个人理解变量的赋值不算使用,变量的赋值可以理解为变量的初始化,变量的使用可以理解为参与了某些运算或者方法的调用,就是说既然涉及到使用,就应除了变量本身还有第三方变量或者算法参与,使用了某个变量必然对整个程序产生了一定影响,这才叫使用,比如变量String s,调用了s.split方法,这算使用,一个未曾使用过的变量String s 给它赋值 String s = "aa";这个操作对程序没啥影响,也没有第三方代码调用,虽然对这个变量进行了操作,这不能算是使用
int i=0; for(int j=0;j<10;j++,i++){ i=i; } System.out.println(i); 看着个例子,输出i 为10,表明赋值也是被使用,赋值是使用的一种情况,由于i++,使用后加一,可以得出这个结论
public class Test{ static{ x=9; } static int x; }这样能通过编译,也能运行, public class Test{ static{ System.out.println(x); } static int x; }这样却无法通过编译,这是什么原因?
public class Test{ static{ x=9; } static int x; }这样能通过编译,也能运行, public class Test{ static{ System.out.println(x); } static int x; }这样却无法通过编译,这是什么原因?
public class Test{ static{ x=9; } static int x; }这样能通过编译,也能运行, public class Test{ static{ System.out.println(x); } static int x; }这样却无法通过编译,这是什么原因?
public class Test{ static{ x=9; } static int x; }这样能通过编译,也能运行, public class Test{ static{ System.out.println(x); } static int x; }这样却无法通过编译,这是什么原因?对于静态变量和实例变量,在没有声明之前,只可以存在在赋值运算符(=)的左边. 对于局部变量,必须先声明,才能赋值,然后才能使用.
public class Test{ static{ x=9; } static int x; }这样能通过编译,也能运行, public class Test{ static{ System.out.println(x); } static int x; }这样却无法通过编译,这是什么原因? 输出语句里面的变量x你没有定义就直接使用了。编译就过不去了,程序是从上到下运行的。
int i=0;
for(int j=0;j<10;j++,i++){
i=i;
}
System.out.println(i);
看着个例子,输出i 为10,表明赋值也是被使用,赋值是使用的一种情况,由于i++,使用后加一,可以得出这个结论
public class Test{
static{
x=9;
}
static int x;
}这样能通过编译,也能运行,
public class Test{
static{
System.out.println(x);
}
static int x;
}这样却无法通过编译,这是什么原因?
public class Test{
static{
x=9;
}
static int x;
}这样能通过编译,也能运行,
public class Test{
static{
System.out.println(x);
}
static int x;
}这样却无法通过编译,这是什么原因?
public class Test{
static{
x=9;
}
static int x;
}这样能通过编译,也能运行,
public class Test{
static{
System.out.println(x);
}
static int x;
}这样却无法通过编译,这是什么原因?
public class Test{
static{
x=9;
}
static int x;
}这样能通过编译,也能运行,
public class Test{
static{
System.out.println(x);
}
static int x;
}这样却无法通过编译,这是什么原因?对于静态变量和实例变量,在没有声明之前,只可以存在在赋值运算符(=)的左边.
对于局部变量,必须先声明,才能赋值,然后才能使用.
public class Test{
static{
x=9;
}
static int x;
}这样能通过编译,也能运行,
public class Test{
static{
System.out.println(x);
}
static int x;
}这样却无法通过编译,这是什么原因?
输出语句里面的变量x你没有定义就直接使用了。编译就过不去了,程序是从上到下运行的。