Skip to content
Advertisement

Arrays variable in java [closed]

I am new to array concept there is something i cant understand that is i have read somewhere that when we intialize an array like int[] a = {1,2,3,4} ;

then a actually contain the address of memory location of the the first element of that array I havent statrted oop yet but as i know when toString method is used on reference variables it converts the value of an object that the reference variable contains its address to string but why when use

JavaScript

the whole array is printed rather than just first element of array a ? because array a contains the address of first element only

Advertisement

Answer

The array was printed because you called Arrays.toString(int[] a) method
Which is implemented by JAVA API
https://docs.oracle.com/javase/7/docs/api/java/util/Arrays.html#toString(int[])

JavaScript

For more clarity related to arrays memory representations,
Kindly check the below diagram:

enter image description here

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement