File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
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: 9466

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 agree. Here's the link:
subject: Accessing variables inside method
It's not a secret anymore!