aspose file tools*
The moose likes Beginning Java and the fly likes static block reading values from other class static block Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "static block reading values from other class static block" Watch "static block reading values from other class static block" New topic
Author

static block reading values from other class static block

sanju dharma
Ranch Hand

Joined: Oct 19, 2000
Posts: 45
Hi,
I have one static class , say , Database.java and other class DbConnection.java. I have static block in both classes. Can I use static variable values from one class into static block of another class. I mean what happens if second class gets loaded ( JVM ) earlier than second class. Will first class's value be null ? For example
public class DbConnection {
static {
if(Database.bInsert)
// do something
}
what will happen if DbConnection gets loaded first than Database. Will bInsert value null/default?
Thanks,
Sudhir
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Give it a try. Let's say A references B in a static block. The first time you reference A its static block is evaluated, and it references B so B's static block is evaluated before you can "get" anything from it. Ought to work fine. If for some reason you reference B first, it will be initialized before A, and that's just fine.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: static block reading values from other class static block