Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A sample question - Execution flow

 
Dasa Beg
Greenhorn
Posts: 5
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

I have a question regarding to an example which is listed as a "sample question on the Oracle-Site (http://education.oracle.com/pls/web_prod-plq-dad/db_pages.getpage?page_id=303&p_certName=SQ1Z0_803):






What is the result?
A) c x y g
B) c g x y
C) x c y g
D) x y c g
E) y x c g
F) y c g x

The correct answer would be D.

What I do not understand:

Starting from the main method, a new instance is created and the execution goes to the constructor. I thought that then the line System.out.println("c"); would be printed, but that is not the case.
The execution goes straight to the static block, and the line System.out.println("x");.
Even tough, after x was printed, the flow jumpes to the line System.out.println("y"); and then the constructor block is printed System.out.println("c");.

The execution process in this example is a little bit unclear (to me).

Thanks in advance and best regards!



 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi A Om,

First of all, a warm welcome to CodeRanch!

A Om wrote:The execution process in this example is a little bit unclear (to me).

Read this topic and your doubts will probably be cleared. If not, just reply with your (new) doubts & questions.

Hope it helps!
Kind regards,
Roel
 
Dasa Beg
Greenhorn
Posts: 5
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An excellent explanation!

Thanks once again!

Kind regards

 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nice to know: instead of making a "thank you" post, you could also the post(s) which you liked. It's easier, faster and other ranchers will see immediately which are the "starred" posts.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic