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

OCA chapter 4 - question 22 (Java OCA 8 Programmer I Study Guide, Sybex)

 
Ahson Junani
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can someone please explain me this question and the output. i tried solving but i cannot get it.
 
Claudiu Stroe
Greenhorn
Posts: 29
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At line 3 and 4 in the OrderDriver class you look only for the static result so you have line 2 and line 4,5 (""+"u" = u) . This is duplicated so the output till now is :

u u

You have an initalization of the Order object.
First use the static reference and then the initialization blocks so result is "ucr".
Another Object is created so you concatenate to result the initalization blocks "cr". Result from this two initalization is ucrcr.


So ansewer is E
 
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
Ahson Junani wrote:can someone please explain me this question and the output. i tried solving but i cannot get it.

That's a very generic question. What do you not understand exactly about the explanation provided in the study guide?

And if you are unsure about the running order of static and instance initializer blocks, you might want to read the following topics first and then have another go at this practice question:
  • the running process of the following code
  • Question about the running order of static{} block
  • Order of statics in base and subclasses
  • Order of Initialization on page 19 (Java OCA 8 Programmer I Study Guide)


  • Hope it helps!
    Kind regards,
    Roel
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic