Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

doubt in chapter 3 k&B book  RSS feed

 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is from K&B book. Chapter 3.

Could you please explain how come f1.x==f3.x returns true, because f1.x prints 5 and f3.x prints 6.

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Cathymala:

Remember that when you are passing objects as arguments, you are passing it by reference, so in the FizzSwitch method, you have the x, and z Fizz variables are refering to the same object, so if you are modifying the values in z or even x, you also are modifying the values in f1. Check this printing the value of f1.x before the f1==f3 statement.

Regards,

Alejandro Galvan

--------------------

Preparing SCJP
 
cathymala louis
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello ..
Check out this post .It should surely help! ...

Thanks
 
sweta doshi
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello ..
Check out this post .It should surely help! ...
http://www.coderanch.com/t/266948/java-programmer-SCJP/certification/help


Thanks
 
I am going to test your electrical conductivity with this tiny ad:
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!