This week's book giveaway is in the OCAJP forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
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

Win a copy of OCA Java SE 8 Programmer I Study Guide 1Z0-808 this week in the OCAJP forum!
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: 24189

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