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

object instantiation VS initialization

 
lavnish lalchandani
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
What happens first (i) object intialization OR (ii) object instantiation
 
Bill Shirley
Ranch Hand
Posts: 457
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
object instantiation involves allocating memory for the new instance to exist,

object initialization involves setting the values of the new instance to an initial state (via calls to the constructors)



which do you think occurs first?
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How could you possibly initialize an object that didn't exist?

Where did this question come from - another interview question?

If you want to get picky, in one of the first steps in object instantiation the JVM sets the allocated memory to zero so initialization starts then.

Bill
 
Rob Spoor
Sheriff
Pie
Posts: 20608
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not an intermediate question
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic