This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP 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: 20608
63
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: 12185
34
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