-3

In java, arrays can be created as int[] arr = {value1, value2, value3,.....}. Here we are not using the "new" keyword.So how do we say that array is an object in java?

  • 1
    It's using literal notation. Just as you can do `String a = "b";` and don't have to do `String a = new String("b");` and `a` is still an object, the array is declared and initialized with a literal without `new` and is still an object. – Andrew Li Mar 25 '17 at 13:57
  • 1
    It depends, as with most implementations of most languages, all memory allocated by you is allocated as an object. Though some people subscribe to the idea that only `class` objects are _really_ objects, which I hate, but I suppose it does clear up ambiguity when talking about a language like Java in everyday terms. – George Mar 25 '17 at 14:01
  • It's just a syntax shortcut, array can still be created with `new` keyword like `int[] ints = new int[10];` – shizhz Mar 25 '17 at 14:19
  • -Andrew Li String a = "b" is related to "b" present in the string pool .Can you please explain in context to array? – Master_slave Mar 25 '17 at 14:34

2 Answers2

0

The Java language specification says so (http://docs.oracle.com/javase/specs/jls/se7/html/jls-10.html):

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.

LppEdd
  • 20,274
  • 11
  • 84
  • 139
0

Java specifications says: "An object is a class instance or an array. "

Kamil Gołąbek
  • 65
  • 1
  • 10