• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

doubt in chapter 3 k&B book

 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello ..
Check out this post .It should surely help! ...
https://coderanch.com/t/266948/java-programmer-SCJP/certification/help


Thanks
 
reply
    Bookmark Topic Watch Topic
  • New Topic