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

前端 未结 10 2581
青春惊慌失措
青春惊慌失措 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:52

    See the docs:

    The Object class, in the java.lang package, sits at the top of the class hierarchy tree. Every class is a descendant, direct or indirect, of the Object class. Every class you use or write inherits the instance methods of Object. You need not use any of these methods, but, if you choose to do so, you may need to override them with code that is specific to your class.

    The Object class simply defines the basic state that all objects must have - Like comparing it to other objects.

    It's the parent class of everything. It simply provides kind of template to all the derived objects.

提交回复
热议问题