how array is an object in java?
What is an object?
An array in Java is an object. In Java, we can create arrays by using new operator and we know that every object is created using new operator.
Hence we can say that array is also an object. Now the question also arises, every time we create an object for a class then what is the class of array?
In Java, there is a class for every array type, so there’s a class for int[] and similarly for float, double etc.
In the Java programming language, arrays are objects, are dynamically created, and may be assigned to variables of type Object. All methods of class Object may be invoked on an array.
For every array type corresponding classes are available and these classes are the part of java language and not available to the programmer level. To know the class of any array, we can go with the following approach:
// Here x is the name of the array.
System.out.println(x.getClass().getName());
Hi Manav, as you are not responding to this thread, I am marking your doubt as Resolved for now. Re-open it if required.
Please mark your doubts as resolved in your course’s “ Ask Doubt ” section, when your doubt is resolved.