• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can't understand the Output

 
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



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
 
Ranch Hand
Posts: 433
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 :

System.out.println(B);
now see how things work:


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

Similarly When
System.out.println(A);



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

similarly
A + B + C = 4 + 2 + 1 = 7
 
Dean Jones
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot Sunny.
 
I got this tall by not having enough crisco in my diet as a kid. This ad looks like it had plenty of shortening:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic