This week's book giveaway is in the JavaFX forum.
We're giving away four copies of Introducing JavaFX 8 Programming and have Herbert Schildt on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Can't understand the Output Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Introducing JavaFX 8 Programming this week in the JavaFX forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Can Watch "Can New topic

Can't understand the Output

Dean Jones
Ranch Hand

Joined: Dec 29, 2007
Posts: 129

Can some one please explain why the output changes when we change the order of A+B+C to B+C+A or any other combination
Sunny Jain
Ranch Hand

Joined: Jul 23, 2007
Posts: 433

this problem is actually how constant are initialize and how super interface are called in JAVA, let me try to explain you :

Suppose you write :

now see how things work:

in case when B is called first values are :
B =2, C =1, A =0

Similarly When

so A =4,B = 2, C = 1

similarly when C is called first :
C =3,A = 2, B =1

so when you call B+C+A
you get : 2 + 1 + 0 = 3

A + B + C = 4 + 2 + 1 = 7

Thanks and Regards,
SCJP 1.5 (90%), SCWCD 1.5 (85%), The Jovial Java, java.util.concurrent tutorial
Dean Jones
Ranch Hand

Joined: Dec 29, 2007
Posts: 129
Thanks a lot Sunny.
I agree. Here's the link:
subject: Can't understand the Output
It's not a secret anymore!