File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Can they mix??? 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 "Can they mix???" Watch "Can they mix???" New topic
Author

Can they mix???

K Ville
Ranch Hand

Joined: Aug 16, 2003
Posts: 58
Given:
private static final transient Double balance = null;
Can final and transient mix? Madame Sierra's book states that an instance variable marked transient CANNOT be final or static!


Thinking is the talking of the soul with itself...-Plato
Alton Hernandez
Ranch Hand

Joined: May 30, 2003
Posts: 443
It looks like there is nothing wrong with that combination. But perhaps Madame Sierra or Sir Bert could give a much better explanation.
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8904


[ September 02, 2003: Message edited by: Pradeep Bhat ]

Groovy
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
"transient" is redundant because "static" varaibles are always "transient". But there is nothing wrong with specifying both.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8803
    
    5
K -
I'm trying to find where we said that in the book (can you help with a page number?)... anyway here's what I did find that's close:
'The transient modifier applies only to instance variables'.
Your compiler might let you mark a static variable as transient, but static variables aren't part of an object's persistent state, so it's really meaningless. (It's not on the exam and the spec doesn't say.)
'Instance variables can -
Be marked as final or transient'
I guess we should have said 'final and/or transient'
Does that help?
-Bert


Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Vad Fogel
Ranch Hand

Joined: Aug 25, 2003
Posts: 504
What can't be combined is volatile and final modifiers if it feels close to transient and final. Using both altogether will cause a compiler error. This combination is not in the K&B book, so I'm not sure if the exam's objectives require you to memorize that.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can they mix???
 
Similar Threads
valid combinations of Modifiers like static,native,transient etc
Tranient variable, help!
transient variables
spot the difference: public static final
static / transient