我写了以下代码:
package staticshow;
public class StaticDemo {
static int a = 3;
static int b = 4;
static {
System.out.println("Voila! Static block put into action");
}
static void show() {
System.out.println("a= " + a);
System.out.println("b= " + b);
}
}
public class StaticDemoShow {
public static void main() {
StaticDemo.show();
}
}
Run Code Online (Sandbox Code Playgroud)
我收到错误消息:
The public type StaticDemo must be defined in its own file
Run Code Online (Sandbox Code Playgroud)
第一行中的错误public class StaticDemo {.为什么会这样,我该如何解决?请注意,我的项目名称是StaticDemoShow,包名称staticshow和类名称在代码中给出.
编辑 - 在只公开一个类或两个类默认后,我收到错误"选择不包含主类型".那我该怎么办?