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

前端 未结 8 1685
梦毁少年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:19

    Also one other point that many answers missed to point out is that without the public declaration, the JVM would never know which classes' main method needs to be invoked. All classes declared in one .java file can all have main methods, but the main method is run on only the class marked as public. HTH

提交回复
热议问题