Win a copy of Bad Programming Practices 101 (e-book) this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

is it a Object?  RSS feed

 
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??
 
Sheriff
Posts: 21370
91
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).
 
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...

 
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?
 
lowercase baba
Bartender
Posts: 12626
50
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.
 
You are HERE! The other map is obviously wrong. Better confirm with this tiny ad:
Why should you try IntelliJ IDEA ?
https://coderanch.com/wiki/696337/IntelliJ-IDEA
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!