package com.CSDN;
public class HelloWorld {
public static void main(String []args){
System.out.println("I love U");
int x = 10; //1
System.out.println(x);
}
class ABC {
int f = 10; //2
System.out.println(f);//錯誤! 因爲int f = 10;是執行語句,只能在方法中
}
}
之所以1處不報錯,是因爲在main方法裏。
而2處報錯,是因爲類ABC中沒有把執行語句"int f = 10;"放到方法中
拋出錯誤:
Multiple markers at this line
- Syntax error on token(s), misplaced construct(s)
- Syntax error on token “f”, VariableDeclaratorId expected after this
token