Why main method is marked as public?

前端 未结 9 1188
情书的邮戳
情书的邮戳 2020-12-10 08:41

I have a question that why main method is marked as public?

According to an answer on stackoverflow, It is declared as static

9条回答
  •  Happy的楠姐
    2020-12-10 08:48

    Yes the standards say so that main method should be public in Java. But it's not only for Java. However even for C#, main must be public.

    So just think about it in real world scenarios.

    E.g. you want to enter your room, but you should enter your home main door first (given room is inside the house...and no other means to enter the house)

    Main door is the only publicly available access point.

提交回复
热议问题