Why doesn't the class containing main have to be public?

前端 未结 3 1761
迷失自我
迷失自我 2020-12-18 10:31

I declared the following class

class A { //not public
  public static void main(String args[]) {
     System.out.println(\"done\");
 }

When

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-18 11:18

    When you declare a class private, you're not making it "invisible", and the same goes for your methods. Declaring a method private simply means it's not callable from outside your class. A static public method of a private class is publicly callable.

提交回复
热议问题