GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes Is every array an Object? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Is every array an Object?" Watch "Is every array an Object?" New topic
Author

Is every array an Object?

Vinoth Kumar Kannan
Ranch Hand

Joined: Aug 19, 2009
Posts: 276

Consider this declaration,]int[] arr = new int[10];
Since we use the 'new' operator - doesn't this mean, arr is an object?
Moreover arr.toString() inside System.out.println(), does not throw any error either!


OCPJP 6
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18876
    
  40


yes


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Vinoth Kumar Kannan
Ranch Hand

Joined: Aug 19, 2009
Posts: 276

Object of type - what?
In the above case will, arr be an object of type Integer?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18876
    
  40

vinoth kumar k wrote:Object of type - what?
In the above case will, arr be an object of type Integer?


No. The primative int array directly subclasses from the Object class... and the type is int[] (int array).

Henry
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

See JLS - Arrays.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
subhash kumar
Ranch Hand

Joined: Jul 14, 2010
Posts: 63
In the Java programming language arrays are objects , are dynamically created, and may be assigned to variables of type Object . All methods of class Object may be invoked on an array.

int[] arr = new int[10];

here arr reference variable pointing to object of "Object" Class

An array object contains a number of variables. The number of variables may be zero, in which case the array is said to be empty. The variables contained in an array have no names; instead they are referenced by array access expressions that use nonnegative integer index values. These variables are called the components of the array. If an array has n components, we say n is the length of the array; the components of the array are referenced using integer indices from 0 to n-1, inclusive.


Subhash Kumar
Attitude is everything
 
GeeCON Prague 2014
 
subject: Is every array an Object?