Why is java “highest” superclass called “Object”?

2019-07-19 02:36发布

问题:

I have a strange (and maybe silly) question: I was wondering.... why is java "Object" class called "Object", not "Class"?

For example, for ArrayList whe have the following hierarchy

Object ->
Collection ->
List ->
ArrayList 

Ok: ArrayList is a List... List is a Collection... but a Collection (the class of all collections) is not an Object... it is a class!

回答1:

Think about what the object itself is. An ArrayList is a list, yes? It's also an object. It's not a class of object. The class name describes what instances of that class represent.

A collection isn't a class of collections - it's a collection (and it's an object).



回答2:

Well, you use Object to declare an instance of a (not better specified) Object, same as you use Collection to declare an instance of a Collection.

You can declare an object of type Class too, with java.lang.Class<T>, where an instance of it represents the Class of the Object



回答3:

Collection is an interface (effectively a special type of class).

A Collection is an object.



回答4:

Your assumption is incorrect. The correct hiearchy for ArrayList is:
ArrayList --> AbstractList --> AbstractCollection --> Object

So even ArrayList has Object as the first thing in its hierarchy.



标签: java oop object