迹忆客 专注技术分享

当前位置:主页 > 学无止境 > 编程语言 > Java >

Java 中错误 Error: Class, Interface, or Enum Expected 修复

作者:迹忆客 最近更新:2023/05/16 浏览次数:

Java 是一种面向对象的强类型编译语言,具有类的概念来利用编程的不同方面,如继承和多态性。 本文将介绍编译时错误 error: class, interface, or enum expected


Java中类定义后的额外花括号错误

考虑下面的代码示例,其中特意在代码示例的最后一行添加了一个额外的大括号。

public class MyApp
{
    public static void main(String[] args) {
        System.out.println("Hello World");
    }
}
}//remove this to fix

上述代码示例在代码编译时出现以下错误。

MyApp.java:7: error: class, interface, or enum expected
}
^
1 error

Java中类定义后函数定义错误

考虑以下代码示例,其中在类定义之后有意定义了一个额外的函数。

public class MyApp
{
    public static void main(String[] args) {
        System.out.println("Hello World");
    }
}

public int add(int a) {
    int b = a + 5;
    return b;
}//move this function (add) inside the MyApp class to fix

这是编译此代码示例时获得的错误。

MyApp.java:8: error: class, interface, or enum expected
public int add(int a) {
       ^
MyApp.java:10: error: class, interface, or enum expected
    return b;
    ^
MyApp.java:11: error: class, interface, or enum expected
}
^
3 errors

在 Java 中定义枚举时使用额外的括号

考虑代码示例,它显示了 Java 中的枚举,末尾有一个额外的大括号。

public enum Day {
    SUNDAY, MONDAY, TUESDAY, WEDNESDAY,
    THURSDAY, FRIDAY, SATURDAY
}
}//remove this to fix

这是编译代码示例时得到的错误。

Day.java:5: error: class, interface, or enum expected
}
^
1 error

转载请发邮件至 1244347461@qq.com 进行申请,经作者同意之后,转载请以链接形式注明出处

本文地址:

相关文章

Solution for Flickering During Vue Template Parsing

发布时间:2025/02/21 浏览次数:103 分类:Vue

Solution for Flickering During Vue Template Parsing, Recently, while working on a project, I noticed that when the internet speed is slow, the screen flickers and the expression message appears. This happens because when the internet speed i

Pandas DataFrame sort_index()函数

发布时间:2024/04/21 浏览次数:119 分类:Python

本教程介绍了我们如何使用 pandas.DataFrame.sort_index()方法,根据索引对 Pandas DataFrame 进行排序。

扫一扫阅读全部技术教程

社交账号
  • https://www.github.com/onmpw
  • qq:1244347461

最新推荐

教程更新

热门标签

扫码一下
查看教程更方便