Java 关于执行语句只能存放在方法体,不能直接在类中编写。Multiple markers at this line - Syntax error on token(s), misplaced c

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

在这里插入图片描述

发布了41 篇原创文章 · 获赞 6 · 访问量 3362

猜你喜欢

转载自blog.csdn.net/Pan_ZC/article/details/105232370
今日推荐