• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

OCAJP question (Q37, Enthuware)

 
Katy Paren
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi.
The output of this code is

Beta44
4,44
Beta44
4,44

I dont understand why output in this order?
 
Campbell Ritchie
Sheriff
Posts: 51349
87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You appear to have landed in the wrong location; this forum is for discussing the website. I shall move you to a location suitable for that question.
You must tell us where you got that question from, otherwise there may be copyright problems
 
Campbell Ritchie
Sheriff
Posts: 51349
87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please start by indenting the code correctly; we have some suggestions here. If you have the code poorly formatted like that, you will never be able to read it.
Then go through the code by following the order of execution with your finger on the screen (or print it and use a pencil) and you should be able to see why the Beta prints out before any of the numbers.
 
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
Katy Paren wrote:I dont understand why output in this order?

This code snippet (and its output) is already explained in great detail in this topic. So I'm pretty sure when you have carefully read this excellent topic you'll have a perfect understanding why this output is printed. If you still have doubts and/or questions, just let us know by replying to this topic.

Hope it helps!
Kind regards,
Roel

PS. When posting a question, code snippet or statement from another resource, you should always QuoteYourSources! Because I am already familiar with this code snippet, I updated the subject with the question number and source of this code snippet.
 
Scott Selikoff
author
Saloon Keeper
Posts: 4031
18
Eclipse IDE Flex Google Web Toolkit
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great reason why you should never hide variables in a parent class! While this done as part of mock exam questions, it is strongly discouraged in practice.

Also, great reason to never make instance variables public! Encapsulation is your friend.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic