Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Rani Singh   on Nov 06 In Java Category.

  
Question Answered By: Bernard Gutierrez   on Nov 06

public class  test1 {

public static  void main(String[] args) {
int a[];
a=new int[2];
[Arman Melkumyan] you vahe not initialized these a[0] and a[1]
elements, that is why you get a ‘0’ value.
In java, you get always ‘0’ default value for “int” type like you have
a default “null” for non initialized objects.

You can also write : a = new int[] { 26 , 33 };

System.out.print(a);


}
}

when i print  just a i get a junk value : [I@77d134
[Arman Melkumyan] junk is a location  of a


but when i print a[0] or a[1] i get 0.


My question  is

What is this junk value ? is it the junk in the
memory location of a ? if so why should java  allocate
memory  locations one for a one for a[0] and one for
a[1] when i tell the jvm  to allocate  just 2 locations
of memory ?

Share: