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

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

    The reason is the same as for the door plates. If some person officially resides in the office (declared public) his/her name must be on the door tag. Like "Alex Jones" or "Detective Colombo". If somebody just visits the room, talks to an official or cleans the floor, their name does not have to be officially put on the door. Instead, the door can read "Utilities" or "Meeting room".

    Official name or MyClass.java Meeting room or Test.java

提交回复
热议问题