如果我不指定,我的课程放在哪个默认包中? [英] What is the default package in which my classes are put if I don't specify it?

查看:25
本文介绍了如果我不指定,我的课程放在哪个默认包中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个名为 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.

这篇关于如果我不指定,我的课程放在哪个默认包中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆