This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Interface instant variables Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Interface instant variables" Watch "Interface instant variables" New topic
Author

Interface instant variables

Henry Zhi Lin
Ranch Hand

Joined: Nov 04, 2008
Posts: 69
Another question for you guys, it from John Meyers' mock test.



The code has compilation error on line 2.

My question is why the compilation pass the line 1? n is a final as well?


SCJP 5.0
Henry Zhi Lin
Ranch Hand

Joined: Nov 04, 2008
Posts: 69
Just had another thought, it pass line one because it change the n's object's x value, but does not change reference n to other object (still point to the old object with x changed). Unlike n, number++ change it reference to other primitive object?

Am I right?
[ November 07, 2008: Message edited by: Henry Zhi Lin ]
Rekha Srinath
Ranch Hand

Joined: Sep 13, 2008
Posts: 178
Yes you are right Henry..
Once a value is assigned to a final wrapper object, its value cannot be changed.
See this link for a related post:
http://www.coderanch.com/t/270629/java-programmer-SCJP/certification/Immutability-Wrapper-Objects
Henry Zhi Lin
Ranch Hand

Joined: Nov 04, 2008
Posts: 69
See you post, and thanks for your explain.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Interface instant variables
 
Similar Threads
Why final object value can be change whereas final variable value can't?
object creation in GC
Starting a new line with FileWriter class
Converting Number to Word
program correction