• Post Reply Bookmark Topic Watch Topic
  • New Topic

EYE OPENER - Program Control Flow  RSS feed

 
karan khosla
Greenhorn
Posts: 25
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This Example is really an EYE OPENER for many who think that main() method is executed first when the bytecode get's loaded into the VM.




Run this Program and see the output. Please watch out for the comments in the code for better understanding. If you think this example really helps you then please reply.



 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's the big surprise here? That the static block is called before the main method? This is just normal documented behaviour. Or are you suggesting something else happens?
 
John de Michele
Rancher
Posts: 600
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Karan,

Have you tried switching the order around in your file (i.e., moving the class definition of Super after Sub)? I think you'll find that Super's static block gets executed before Sub's because it's the parent class, not because it comes first in the file.

John.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!