为什么在下面的代码中为可接受的静态变量赋值,但是使用相同的变量却不是?
class Test
{
static
{
var=2; //There is no error in this line
System.out.println(var); //Why is there an error on this line if no error on the above line
}
static int var;
}
Run Code Online (Sandbox Code Playgroud) byte b=12;
b >>= 2; // Why is this legal? why does it automatically typecasts?
b = b >> 2; // Why is this illegal if the above is legal
Run Code Online (Sandbox Code Playgroud) java ×2