• Post Reply Bookmark Topic Watch Topic
  • New Topic

how many objects created  RSS feed

 
Rajeshwari Natarajan
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How many objects are created on running this simple Hello World program?
 
Francis Siu
Ranch Hand
Posts: 867
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Rajeshwari
One object is created
String[] args
thanks
 
Francis Siu
Ranch Hand
Posts: 867
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry
String[] args //is a reference
no object is created
thanks
 
Don Kiddick
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A few more I think.
1. The args[] is created.
2,3,4. The System class is loaded which will create the static members of that class, err, in and out.
5. The String "Hello World!" is created.
On top of this any number of non-visible objects may get created.
D.
 
Rajeshwari Natarajan
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think "Hello World" String is the only object created.
out is a static member of System class.
 
Don Kiddick
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
static members are objects and need to be created before use. They get created when the class is loaded.
D.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This question can't be answered - the JVM may create as many objects as it likes, and may try to optimize away as many instanciations as it can.
 
Francis Siu
Ranch Hand
Posts: 867
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see.........
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!