This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Accessing variables inside method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Accessing variables inside method" Watch "Accessing variables inside method" New topic

Accessing variables inside method

Romeo Ranjan
Ranch Hand

Joined: Feb 23, 2009
Posts: 95
source: irix technologies

The answer is 55667766. i can trace the answer upto 556677,but i am not sure why System.out.print( voo.doo.doolet ); gives 66 in the end?

Thanks in advance

SCJP 6.0
Ankit Garg

Joined: Aug 03, 2008
Posts: 9400

The secret is in line number 7, when doo = new Doo( ); is executed, the doo in voolish method starts pointing to a different object of type Doo, so the actual doo object passed to the method isn't effected when we set doo.doolet to 77. Read this, it will clear your doubts...

SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: Accessing variables inside method
It's not a secret anymore!