It's not a secret anymore!
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Transient Variable 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 "Transient Variable" Watch "Transient Variable" New topic

Transient Variable

Ashish Agarwal
Ranch Hand

Joined: Dec 02, 2000
Posts: 36
Its written in R&H that transient variables cannot be Static or
final. See Pg-90.
But the following code compiles and run fine.
Can anybody explain.
class test13{
transient static int x = 85;
transient final int y = 85;
transient final static int z = 85;
public static void main(String args[]){
public static void print(){
Tony Alicea

Joined: Jan 30, 2000
Posts: 3226
OK; I'm on vacation on The Beach (Atlantic Ocean)... Translation: I have no compiler with me
But if you are willing to accept a somewhat educated answer
I don't see the conflict in a variable being static, final, or transient.
For Serialization purposes, neither static nor transient variables are included in the byte stream that is the result of Serialization.

Tony Alicea
Senior Java Web Application Developer, SCPJ2, SCWCD
Lisa Yu

Joined: Dec 27, 2000
Posts: 3
From R&H's errata :
Page 90
Corrected in the third printing: The Note on the page should be deleted.
Ashish Agarwal
Ranch Hand

Joined: Dec 02, 2000
Posts: 36
Thanx Lisa
I agree. Here's the link:
subject: Transient Variable
It's not a secret anymore!