What is the default package in which my classes are put if I don't specify it?

后端 未结 3 509
误落风尘
误落风尘 2020-11-27 20:46

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.prin         


        
3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-27 21:28

    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.

    The JLS says that:

    Unnamed packages are provided by the Java SE platform principally for convenience when developing small or temporary applications or when just beginning development.

提交回复
热议问题