Is it possible to do something like this in Java?
Object[] objArray = { new Car(), new Human() }
I read that the array elements all have to be the same type but aren't these all of type Object ?
Yes, it's possible but not useful often and always dangerous.
If you want to put some objects into a collection (list or array), the type of the collection must allow for a common ancestor. Since Object is the common ancestor to all OO types in Java, you can put anything into it (and, with Java 6's autoboxing, even primitives).
The problems start when you work with the elements in the list. As long as you only need to call methods which the common ancestor type provides, everything is fine.
But eventually, you will want to call methods of the Car type and that means you'll have to identify the instances in the collection (which is somewhat slow and pretty clumsy in the code) and use casts (always a good sign for bad code).
Inheritance is used to define a is-a relationship. Since every class in Java extends java.lang.Object (either directly or indirectly), a Car instance is-a Object instance, and a Human instance is-a Object instance.
So, of course, an array of objects can hold humans, cars, and every other kind of object.
new Object[]before you initialize it, because otherwise the compiler might get confused.Humanbeing treated like anObjectbut I guess that is an ethical question that does not belong here. :P