• 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
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

This code fragment is quite confusing  RSS feed

 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I am not able to undersatnd how output of this code generated by JVM.




Regards,
VIJAY SHAN

[fixed code tags]
[ February 16, 2008: Message edited by: fred rosenberger ]
 
Rancher
Posts: 42973
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tell us what the output is, and what you do or do not understand about it.
 
vijay shanker
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the out put is

true true


why is this output ?
 
Ulf Dittmer
Rancher
Posts: 42973
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The first "true" stems from the fact that f1 and f3 point to the same object (FizzSwitch returns the reference to f1, which then gets assigned to f3). Since "==" compares object references, they are equal. And since they point to the same object, naturally their "x" field is the same.
 
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by vijay shanker:
the out put is

true true


why is this output ?



What output would you have expected?
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!