-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?

4
  • 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. Commented Mar 25, 2017 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. Commented Mar 25, 2017 at 14:01
  • It's just a syntax shortcut, array can still be created with new keyword like int[] ints = new int[10]; Commented Mar 25, 2017 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? Commented Mar 25, 2017 at 14:34

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.