" class has illegal signature-6ren"> " class has illegal signature-我在第 1 行和第 2 行遇到错误。第 1 行表示表达式的非法开始。我不明白为什么第 1 行是非法的 public class MyArt { public static void main(-6ren">
gpt4 book ai didi

Java 类格式错误 : Method "" class has illegal signature

转载 作者:行者123 更新时间:2023-11-30 04:23:48 25 4
gpt4 key购买 nike

我在第 1 行和第 2 行遇到错误。第 1 行表示表达式的非法开始。我不明白为什么第 1 行是非法的

public class MyArt {
public static void main(String argv[]) {
MyArt m = new MyArt();
m.amethod();
}

public void amethod() {
static int i; // line 1
System.out.println (i); // line 2
}
}

最佳答案

您无法在方法内声明静态字段:

public class MyArt {

public static void main(String argv[]) {
MyArt m = new MyArt();
m.amethod();
}
//you can very well have non-static method since you are
//calling it through MyArt object m
public void amethod() {

int i=0; // REMOVED STATIC, otherwise program won't compile
System.out.println (i); // line 2, if not initialized compilation will fail where the variable is refrenced

}
}

关于Java 类格式错误 : Method "<error>" class has illegal signature,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16375126/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com