有如下代码:
package first;public class hwj {
public static void main(String[] args) {
System.out.println("google");
first.hwj383.output();
}}
class hwj383
{
public static void output()
{
System.out.println("baidu");
}
}
但是在class hwj383 类前面加上public修饰符,就会提示错误:
Severity and Description Path Resource Location Creation Time Id
The must bpublic type hwj383 e defined in its own file myjava/src/first hwj.java line 10 1200461966937 4
这是什么原因,默认不是public吗?新手,勿笑.
package first;public class hwj {
public static void main(String[] args) {
System.out.println("google");
first.hwj383.output();
}}
class hwj383
{
public static void output()
{
System.out.println("baidu");
}
}
但是在class hwj383 类前面加上public修饰符,就会提示错误:
Severity and Description Path Resource Location Creation Time Id
The must bpublic type hwj383 e defined in its own file myjava/src/first hwj.java line 10 1200461966937 4
这是什么原因,默认不是public吗?新手,勿笑.
Chapter5
编译单元:Java创建的一个源码文件
每个编译单元都必须有一个以.java结尾的名字。在编译单元的内部,可以有且只能有一个公共(public)类,它必须拥有与文件相同的名字(包括大小写形式,但排除.java文件扩展名);这个编译单元中剩下的类(如果有的话),对于这个编译单元包外面的世界是隐藏的,不可以访问的
源文件的名字要和public的类名一致
这些都是很基础的东西