Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

is it a Object?

 
pras
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
int []a=new int[10];

/***how can you create a object out of primitive types************/

in the above code is 10 objects created or 10 integers??
 
Rob Spoor
Sheriff
Pie
Posts: 20552
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by prasanna sheregar:
int []a=new int[10];

/***how can you create a object out of primitive types************/

in the above code is 10 objects created or 10 integers??

1 object and 10 integers.

The object is the array itself, with inside it 10 integers (all with value 0).
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See JLS - 10 Arrays...
In the Java programming language arrays are objects...
 
nilesh purohit
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
a is a reference variable pointing to an array of ten integers.array is an single object created on the heap
 
pras
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class neeti {

static int year[]; /*****************8DOUBT*********/

public static void main(String args[]) {
System.out.println(year);
}
}

/********** doubt*********************/

is there a object reference there --- the DOUBT line...or is it a primitive?
 
fred rosenberger
lowercase baba
Bartender
Posts: 12148
31
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
'year' is a reference variable. it points to a object that is an Array, and that array can only hold ints. the compiler is kind, and initialized each of those 10 ints to 0 for you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic