You can start a "program" like this with the normal Java launcher; it loads the class in order to look for main(), and loading it will cause this code to run. If this initializer ever returns, though, you'll see the error message about not being able to find main!
That said, I should mention that this old chestnut has been known forever; every book that purports to teach you "advanced Java" trots it out and dusts it off.
Originally posted by Ernest Friedman-Hill: You can start a "program" like this with the normal Java launcher; it loads the class in order to look for main(), and loading it will cause this code to run. If this initializer ever returns, though, you'll see the error message about not being able to find main!
That said, I should mention that this old chestnut has been known forever; every book that purports to teach you "advanced Java" trots it out and dusts it off.
I don't think so........ there must be some other way the java virtual machine is doing in that....and i think static will not return anything.... can you explain with an example...please......
I don't think so........ there must be some other way the java virtual machine is doing in that....and i think static will not return anything.... can you explain with an example...please......
This code:
is a static initalizer block and is executed when the class is loaded (see here for more explanation). As Ernest points out, one could issue the command:
and the JVM would load the class to look for the main() method. The static initalizer is run and it invokes Starter. There is nothing to return because the initalizer is not a method. This is not "advanced" Java. It is obfuscated Java.
Layne Lund
Ranch Hand
Joined: Dec 06, 2001
Posts: 3061
posted
0
Originally posted by j rangavallika: here is the next quest......
interface a{ .... .... }
interface b extends a { .... ... }
now can i connect any other two classes by using these two interfaces.....
What do you mean by "connect any other two classes"?
This sounds an awfully like a homework assignement and doesn't even seem like "advanced" Java. If you explain what you want to do and show us what you have tried already, we can help from there.
is a static initalizer block and is executed when the class is loaded (see here for more explanation). As Ernest points out, one could issue the command:
and the JVM would load the class to look for the main() method. The static initalizer is run and it invokes Starter. There is nothing to return because the initalizer is not a method. This is not "advanced" Java. It is obfuscated Java.
Is there an echo in here?
Ilja Preuss
author
Sheriff
Joined: Jul 11, 2001
Posts: 14112
posted
0
Originally posted by Layne Lund: doesn't even seem like "advanced" Java.
Agreed. Moving to intermediate...
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus