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!
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).
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
Collection
is an interface (effectively a special type of class).
A Collection
is an object.
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.