Java Object superclass

前端 未结 3 1033
长发绾君心
长发绾君心 2021-01-11 12:10

I have a weird Java question:

As we know:

  1. All Java classes extend java.lang.Object
  2. All Java classes cannot extend itself
3条回答
  •  南方客
    南方客 (楼主)
    2021-01-11 12:20

    Object is an exception to the first rule, and has no superclass. From JLS3 8.1.4:

    The extends clause must not appear in the definition of the class Object, because it is the primordial class and has no direct superclass.

    You can also try it out with reflection:

    Object.class.getSuperclass(); // returns null
    

提交回复
热议问题