• Post Reply Bookmark Topic Watch Topic
  • New Topic

This code fragment is quite confusing  RSS feed

 
vijay shanker
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 ]
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • 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: 42972
73
  • 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.
 
Ilja Preuss
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?
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!