首页 > 解决方案 > 为什么“class new {”会给出编译错误“identifier is expected”?

问题描述

import java.util.*;
import java.io.*;
class new 
{
    public static void main(String[] args)
    {
        Scanner scanner = new Scanner(Sytem.in);    
        System.out.println("enter a number...");
        int a = scanner.nextInt();
        System.out.println("the number is " + a);
    }
    
}

它在第 3 行抛出一个标识符错误。声明第 3 行需要一个标识符

new.java:3: error:   <identifier> expected

标签: javacompiler-errorsidentifier

解决方案


该词new属于Java 语言关键字,因此不能用作标识符。


推荐阅读