What is an heterogeneous object in java?
I don't think that heterogeneous objects is a commonly used term that comes witha a clear and well defined meaning.
Thus your definition that says: objects of different classes are heterogeneous is fine.
( The problem arises later, when you assume that other people share that same understanding, and that is not necessarily true )
"homo-" means same, "hetero-" means different.
In any case if a single Java array can only store one type, say, only numbers, or only strings then it is homogeneous.
If multiple types then heterogeneous. In the above case, since collection is of Object type and can hold any type
Let's take Javascript for understanding this better eg. arrays are heterogeneous, because I can make an array that holds [5, "hello", new Object()], and in Java that's not possible.
I've heard this term only once when a heterogeneous object referred to a heterogeneous collection, a collection that can store objects of different types.
A heterogeneous collection could be an Object[]
array, or List<Object>
list. We rarely use them (their declarations are too general - "a collection of everything" indicates design issues), but it's clear that it can contain instances of different types (e.g. Integer
and String
).