-4
public class Demo {
    public static void main(String[] args) {
        int array[]=new int[2];
        System.out.println(array);
    }
}

This an example. Can anybody explain this.

Vishnugk
  • 3
  • 1

2 Answers2

0

You just defined the array and java by default initialized that array context i.e. array[0] and array[1] with default value i.e. 0.

When you will print the array it will just print the type of Array i.e. Int array followed by hashCode something like I@32324.

SMA
  • 36,381
  • 8
  • 49
  • 73
0
// declares an array of integers
int[] anArray;

// allocates memory for 10 integers
anArray = new int[10];

//declares an array of integers and allocates memory for 2 integers
int array[]=new int[2];

And if you want to print that thing use --> this <--

//print the content of the array
System.out.println(Arrays.toString(array));

Because this :

System.out.println(array);

is not going to print the content of your array, it will print the memory address of the array.

Community
  • 1
  • 1
Tahar Bakir
  • 716
  • 5
  • 14