Someone asked me: can an array in java contain integers and float? She received this question from the teacher.
Now my answer is: yes, since you can declare an array of objects and store integers and floats in it.
But now I wonder if this is correct, since technically, when you store Integer and Float objects in an array, it seems to contain both types, but if you βaskβ the array, it will tell you that it contains Objects, and if I do not do bookkeeping or class checking, there is no way to say that the array has integers and floating numbers.
On the other hand, I still feel that this might be the right answer, since theoretically the array contains objects of both types.
So, I ask for a reasonable opinion: if you were asked (in an interview, something in the tests), then in java the array can contain integers and float, yes or no? What would you answer?
source share