• Post Reply Bookmark Topic Watch Topic
  • New Topic

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: 42975
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: 42975
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?
 
machines help you to do more, but experience less. Experience this tiny ad:
Why should you try IntelliJ IDEA ?
https://coderanch.com/wiki/696337/IntelliJ-IDEA
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!