Can transient modifier be specified for a static variable? Acc.to mughal,transient modifier should not be specified to a static variable,as they don't belong to a class. I did write a code using both modifiers and it compiles and runs without any problem. Iam a little confused,pl.clarify.
"should not be" is different than "can not be" -- Transient shouldn't be applied to a static variable because it does not belong to the class... and when you serialize an object, the static variables are not serialized anyway -- so marking one as transient would be silly. If the book said "Transient can not be applied to static variables", you'd get a compiler error.
Geetha A transient variable is one that is not stored as part an objects persistent state. Since static varaibels are not serialized anyway transient does not apply to them. Compilers will allow you to do since it doesn't make any difference one way or the other. hope that helps
but they can ask you if transient or volatile are java keywords. So, keep an eye on them! Francisco
Francisco<br />SCJP<br />please use the [code][/code] tags when showing code.Click <a href="http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=ubb_code_page" target="_blank">here</a> to see an example.
sunglasses are a type of coolness prosthetic. Check out the sunglasses on this tiny ad: