Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

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

 
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.
 
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
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Likes 1
  • 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
     
    catch it before it slithers away! Oh wait, it's a tiny ad:
    Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
      Bookmark Topic Watch Topic
    • New Topic