java - How does Array treat primitive data types as objects? -


i bit new java programming. 2 or 3 days ago, encountered question regarding arrays in mind give below.

every java programmers knows, array collection of objects, doesn't matter whether contains primitive data types or strings.

so question is, if array collection of objects how treats or converts primitive data type objects, because in java, primitive data type different objects(like strings). consider following program:-

   int[] array = new int[3];    array[0] = 1;    array[1] = 2;    array[2] = 4;`    for(int a=0;a<array.length;a++) system.out.println(array[a]); 

i made array or array object using new keyword , datatype follows it. is, of course, workable arrays. when variable, fail.

int var1 = new int 3; 

for attention, asking again, how in java array treats or converts primitive data type objects, since primitive data types not objects.

thank you!

in java, there 2 categories of types: primitive , reference(i.e. objects)

an array type (whether it's primitive array or object array) reference type. exmaple, int[] subtype of object. can call methods in object on int[].

nevertheless, int[] array of primitives, not objects.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -