• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Execution sequence

 
Rahul Kumar
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,,


I want to know the execution sequence..

Whethere the sequence i hav written is correct or not..
1) First static variables
2) Static block
3) Main method
4) Non Static variables..

If anybody has any good link kindly share it...


 
Praveen Babu
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

The Sequence is right but there is one more thing you might want to know
that is , after main method the non-static blocks(eg., blocks like {System.out.println();} ) are executed.Also, first the static variables are initialized with their default values(say 0 for int) then static blocks are executed in order of apperance and then the static variables are executed in order of their appearance

See the code below which shows the same.



and the o/p is:

---------- o/p ----------
static one
static two
5
one
three
two
hmm...


Bye & Regards,
Praveen

[ August 10, 2006: Message edited by: praveen babu ]

[ August 10, 2006: Message edited by: praveen babu ]
[ August 10, 2006: Message edited by: praveen babu ]
 
wise owen
Ranch Hand
Posts: 2023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Initialization
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic