Why does every object in Java implicitly extend java.lang.Object class?

前端 未结 10 2565
青春惊慌失措
青春惊慌失措 2020-11-29 04:21

I have been programming in Java for quite some time, but when I tried to explain what an java.lang.Object class is to a friend, I could not come up with more th

10条回答
  •  南方客
    南方客 (楼主)
    2020-11-29 04:54

    Quoting Head first Java 2nd edition:

    Without a common superclass for everything in Java, there’d be no way for the developers of Java to create classes with methods that could take your custom types... types they never knew about when they wrote the ArrayList class.

    Which essentially explains the need of a generic predefined class type in Java, which can be used to implement the different features provided by the language.

提交回复
热议问题