Java Object superclass

前端 未结 3 1017
长发绾君心
长发绾君心 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:42

    You'd be better off thinking of this as:

    1. All java classes must implement the interface implied by the methods in java.lang.Object.
    2. The concrete class java.lang.Object provides default implementations of these functions.
    3. All other java classes are derived from the object java.lang.Object and may choose to use or override the default implementations of the methods.

    The two main points are: all the classes must implement the implied interface and the Java language spec gives you (forces upon you?) default implementations for these methods for free.

提交回复
热议问题