What is the default package in which my classes are put if I don#39;t specify it?(如果我不指定,我的课程放在哪个默认包中?)
问题描述
假设我有一个名为 Main.java 的文件,其代码如下:
Let's assume I have a file named Main.java with the following code:
public class Main {
public static void main(String[] args) {
System.out.println("Hello world");
}
}
它是否放在一个特定的包中,在(也许?)一个未命名的包中?
Is it put in a specific package, in (maybe?) an unnamed package?
谢谢
推荐答案
不在命名包中的类在 未命名包.因此完整的类名是Main.
A class that is not in a named package is in an unnamed package. Thus the full class name is Main.
此类类不能使用命名包,但通过反射除外.
Such classes cannot be used from a named package, except via reflection.
JLS 说:
Java SE 平台提供未命名的包主要是为了方便开发小型或临时应用程序或刚开始开发时.
Unnamed packages are provided by the Java SE platform principally for convenience when developing small or temporary applications or when just beginning development.
这篇关于如果我不指定,我的课程放在哪个默认包中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如果我不指定,我的课程放在哪个默认包中?
基础教程推荐
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 修改 void 函数的输入参数,然后读取 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
