Why can't a top level class be static in Java?

前端 未结 8 1344
礼貌的吻别
礼貌的吻别 2020-12-04 07:30

Can\'t find a satisfactory answer anywhere.

8条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-04 08:03

    The access modifier supported for top level are class are as follows :

    1) public

    2) default

    3) abstract

    4) final

    5) strictfp.

    Reason: Top level class

    Because the static keyword is meant for providing memory and executing logic without creating Objects, a class does not have a value logic directly, so the static keyword is not allowed for outer class and mainly as mentioned above static can't be used at Package level. It only used within the Class level.

提交回复
热议问题