| Author |
What is the sequence of execution?
|
Joe Harry
Ranch Hand
Joined: Sep 26, 2006
Posts: 8795
|
|
Hi Guys, Consider the sample code below from Dan Chisholm, I want to know what will be the sequence of execution of the above code. I mean, tht static methods are executed in the order in which they are declared??am I right?? If that is the case, then with respect to the above code, m1 should execute first and what will it's parameter be?? I'm confused.
|
SCJP 1.4, SCWCD 1.4 - Hints for you, SCBCD Hints - Demnachst, SCDJWS - Auch Demnachst
Did a rm -R / to find out that I lost my entire Linux installation!
|
 |
Vinayagar Karpagam
Ranch Hand
Joined: Apr 09, 2006
Posts: 72
|
|
|
Did you mean that static code blocks (initializers) are always executed in the order they are written?. If not, I dont think there is anything to relate between static methods and static initializers.
|
 |
Barry Gaunt
Ranch Hand
Joined: Aug 03, 2002
Posts: 7729
|
|
m1 executes first, with a String parameter value of "A". Jothi, have you executed the code (putting in System.out.println's) and read the explanation given by Dan Chisholm? [ December 08, 2006: Message edited by: Barry Gaunt ]
|
Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
|
 |
Joe Harry
Ranch Hand
Joined: Sep 26, 2006
Posts: 8795
|
|
Barry, My confusion is that, we have 3 static methods. Which one will be the first one to be called at compile time and which one is the first one to be called during run time. Please anyone clarify me on this.
|
 |
Barry Gaunt
Ranch Hand
Joined: Aug 03, 2002
Posts: 7729
|
|
Which one will be the first one to be called at compile time
Nothing is going to be called at compile time. At runtime: main, m1, m2
|
 |
Barry Gaunt
Ranch Hand
Joined: Aug 03, 2002
Posts: 7729
|
|
Why don't you just add a few println statements to show where you are?
|
 |
Joe Harry
Ranch Hand
Joined: Sep 26, 2006
Posts: 8795
|
|
|
Thanks Barry.
|
 |
 |
|
|
subject: What is the sequence of execution?
|
|
|