Why can't inner classes declare static members?

前端 未结 5 488
清酒与你
清酒与你 2021-02-01 17:36

The Java Tutorial says that since an inner class is associated with an instance of the enclosing class, it (the inner class) cannot define any static members itself.

It\

5条回答
  •  猫巷女王i
    2021-02-01 18:21

    Why can't inner classes declare static members?

    The inner class is contained in the instance area of ​​the outer class. Therefore, within the inner class, it is not allowed to declare static members. On the other hand, the static inner class is contained in the static area of ​​the outer class. Thus, it is only allowed to declare static members and not instance members.

提交回复
热议问题