How can a primitive datatype like array of integers have a field ‘length’, when it is not a class? e.g.
int a[] = {1,2,3,4};
int j = a.length;
System.out.println(j);
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Simple: arrays are not primitives. Rather, they are objects of a reference type.
Another way to experience this is to see what happens if you pass an array of int into a method and modify the contents of the array from within the method. You’ll see that this will modify the original array object too, as would happen to all variables of reference type (non-primitive).