📄 scope.mj
字号:
/**
* This program is used to test whether your compiler can correctly
* deal with variable scopes.
* The following program is correct and will display nothing.
*/
class Program {
static int i1 = 2;
static int i2 = 4;
static void main() {
if (i1!=2) print("error1\n"); // refer to the global variable i1
if (i2!=4) print("error2\n"); // refer to the global variable i2
{
int i2 = 8;
if (i2!=8) print("error3\n"); // refer to the local variable
// i2 in this block
}
if (i2!=4) print("error4\n"); // refer to the global variable i2
f();
i1();//I add
return;
}
static void f() {
{
int i3 = 16;
if (i3!=16) print("error5\n"); // refer to the local variable
// i3 in this block
}
{
int i3 = 32;
if (i3!=32) print("error6\n"); // refer to the local variable
// i3 in this block
}
int i3 = 64;
if (i3!=64) print("error7\n"); // refer to the local variable
// i3 in this block
}
static void i1() { // The method can have the same name with a
// global variable.
if (i1!=2) print("error8\n"); // refer to the global variable i1
int i1 = 128; // The local variable can hava the same name
// with the method.
if (i1==128) print("error9\n");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -