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