Meaningless Drivel is fun!
The moose likes Java in General and the fly likes Object creation at Compile time Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Object creation at Compile time" Watch "Object creation at Compile time" New topic

Object creation at Compile time

Anil Chandran

Joined: Apr 11, 2005
Posts: 15
Can we create objects at compile time?

Or in a simple sense

String s = "hello world" ;

When is the object created ? Runtime or Compile time ?

Thanks in advance


I started out with nothing..I still have most of it ...
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

All objects are created in the Java VM, while it is running. Some objects, like the String shown here, are created in the VM while a class is being loaded, so it's effectively created before your program code runs; but it's still created at "runtime."

[Jess in Action][AskingGoodQuestions]
I agree. Here's the link:
subject: Object creation at Compile time
It's not a secret anymore!