[问题]请问线上JAVA编辑器为什么这样的语法不行

楼主: chiang0514 (chiang0514)   2021-11-15 20:58:14
请问线上 网页版的JAVA编辑器
在:https://www.tutorialspoint.com/compile_java_online.php
在:https://www.jdoodle.com/online-java-compiler/
在:https://ideone.com/
/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Test{
int a;
}
class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
Test test = new Test();
}
}
Main.java:9: error: class Test is public, should be declared in a file named
Test.java
public class Test{
^
1 error
宣告类别怎么都不能成功编译成功呢?
作者: lycantrope (阿宽)   2021-11-15 21:07:00
class has to be "Main" only if the class is public
作者: LPH66 (-6.2598534e+18f)   2021-11-15 23:34:00
你想像这些地方你的程式是放在 Main.java 里编译的就好
作者: crazybad   2021-11-23 11:45:00
你存盘成 Ideone.java 就不会有问题了
作者: mureka (mureka)   2020-01-07 23:01:00
基本习惯,一个物件一个档(inner class 不算),档名跟物件名相同

Links booklink

Contact Us: admin [ a t ] ucptt.com