Do we inherit from Object?

后端 未结 3 1884
伪装坚强ぢ
伪装坚强ぢ 2021-01-18 19:30

Guys do we inherit from Object like from any other class (except of course that we don\'t have to explicitly state that) or there is some special privileges to Object class

3条回答
  •  醉梦人生
    2021-01-18 20:09

    Every class in Java IS an Object. They behave like Objects, they can be added to collections of type Object, they can use any method defined in Object.

    So, YES, everything (except primitives) inherit from Object in Java.

    EDIT:Java takes the approach of "Everything is an Object". It sort of forces Object Oriented programming.

    Example:

    • If class A does not extend another class it inherently extends Object.

    • If class A extends another class B, it is extends Object as well since B must have extended Object.

提交回复
热议问题