Why does Java allow us to compile a class with a name different than the file name?

前端 未结 8 1719
梦毁少年i
梦毁少年i 2020-12-22 19:20

I have a file Test.java and the following code inside it.

public class Abcd
{
        //some code here

}

Now the class does n

8条回答
  •  抹茶落季
    2020-12-22 20:01

    The Java specification states you can only have at most one public class per file. In this case, the class name should match the file name. All non-public classes are allowed to have any name, regardless of the file name.

提交回复
热议问题