Should all the elements in Java arrays be of the same type?
All the elements in Java array should be of the same type except for cases allowed by polymorphism. When you create an array, you should specify the type of elements that can be contained in it. If it is not a primitive type but a type defined through some class, then the actual array, in addition to objects of the specified class, may also contain objects of the classes that are, in turn, subclasses of the class that was specified in the initial array declaration.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
Java quizzes
Sign Up Now
or Subscribe for future quizzes