-2

Why for finding the length of the array it is like

array.length;

and not

array.length();

I know array is not a class and so length is not a function so no (); If length is not a function then what is it and how does it return length? If array is not a class then what is it? What does the compiler do when it finds array and how does it implement it does it make multiple variable?

anjani
  • 45
  • 11
  • 1
    The third duplicate that was added goes into some detail on where in the JLS `length` is specified. – Makoto Jun 23 '17 at 05:11

1 Answers1

2

To answer your question if an array is an object or not:

From the Java docs:

In the Java programming language, arrays are objects (§4.3.1), are dynamically created, and may be assigned to variables of type Object (§4.3.2). All methods of class Object may be invoked on an array.

See: http://docs.oracle.com/javase/specs/jls/se8/html/jls-10.html

To answer what "length" is:

You are merely accessing the length field and not invoking a call to a function.

Joey Ezekiel
  • 1,017
  • 1
  • 11
  • 26