In Java we can declare an array using the following:
String[] array = new String[10]; int size = array.length;
Does this mean that the array itself is an object? I ask, because in C++ an array is just a pointer and does not have any methods.
No, arrays are not primitive datatypes in Java. They are container objects which are created dynamically. All methods of class Object may be invoked on an array. They were considered as reference data types.
Array is considered to be an object in Java. The reason behind this is that an array can be created using the 'new' keyword. The 'new' keyword/operator is always used to create an object. This is how an array is perceived as an object.
An array can be considered to be an object with the following properties/keys: Length - This can be 0 or above (non-negative). The array indices. By this, I mean "0", "1", "2", etc are all properties of array object.
Yes, the docs say so: An array is a container object that holds a fixed number of values of a single type. Note that array types of primitive types (like int[] or char[] ) themselves are also objects.
Yes.
The Java Language Specification section 4.3.1 starts off with:
An object is a class instance or an array.
Yes; the Java Language Specification writes:
In the Java programming language, arrays are objects (§4.3.1), are dynamically created, and may be assigned to variables of type Object (§4.3.2). All methods of class Object may be invoked on an array.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With