aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes transient variable Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "transient variable" Watch "transient variable" New topic
Author

transient variable

Sandra Marti
Ranch Hand

Joined: Jun 08, 2000
Posts: 63
This question is from Poddler's mock exam ( I got this from maha anna's mock exam list).
This is how it goes,
Question : The following declaration (as a member variable) is legal
static final transient int maxElements = 100;
A. True
B. False

The answer given is A. That is 'True'. But I think it should be false as 'Transient variable may not be final or static' (page 90 of RHE).
[This message has been edited by Sandra Marti (edited July 19, 2000).]
hemanshow
Greenhorn

Joined: Jun 26, 2000
Posts: 25
1.static: A transient variable can't be static as only variables attached to objects r relevent to be made transient. Its no use to make a class variable transient as class variable can't be serialized/de-serialized.
2.final: I also read that final vraibles can't be static, can't relate tho. May be that while object is being de-serialized, its not possible for JVM to assign value to the final variable??
right?
Ajith Kallambella
Sheriff

Joined: Mar 17, 2000
Posts: 5782
Guys,
Have you tried compiling this line of code. There is absolutely nothing wrong with it and it is a perfectly legal declaration.
Static means the variable is bound to the Class object instead of an object instance. However, it can still be accessed via the object instance and can be treated as an instance variable. Being static has nothing to do with being final or being transient.
Similarly, final means once initialized, it cannot be changed. It doesn't mean it cannot be or should not be serialized!. Again, final, static and transient are keywords which serve different intents and are not mutually exclusive.
Hope this helps
Ajith


Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
Sandra Marti
Ranch Hand

Joined: Jun 08, 2000
Posts: 63
Thanks Ajit and Hemanshow
I found that this was already discussed in an earlier thread and apparently the statement in RHE is wrong. I better refer to the errata.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: transient variable
 
Similar Threads
Can transient variables be declared final or static ?
Transient
Three Little Questions
Tranient variable, help!
static members are un-serializable??