Hi, This is from deepak's mock. Which one of the following statements is true ? A.Transient variables are not serialized. B.Transient methods may not be overridden. C.Transient methods must be overridden. D.Transient classes may not be serialized. E.Transient variables must be static. How to make sure about the declaration of transient variables and volatile? Thanks and Regards Sudha
Milind Mahajan
Ranch Hand
Joined: Oct 23, 2000
Posts: 77
posted
0
Hi, I think answer A is right. B, C and D are wrong because transient modofier can be applied only to variables. D is wrong because transient varibles should not static. volatile modifer can be, again, applied only to variables. It tells the compiler not to do any optimisation for that variable ( in a loop ) because that variable can be modified asynchronously by some other thread ( this sentence is alomost straight out of some book :-)). There is an example of using volatile modifier in Threads chapter of Patrick/Schildt book. Hope this helps. Milind
Jonathan Jeban
Ranch Hand
Joined: Oct 08, 2000
Posts: 52
posted
0
Hi Milind , Agree with ur answers except for the explanation for D.
Originally posted by Milind Mahajan: D is wrong because transient varibles should not static.
Transient Variables can be static . But D is wrong because ,it says transient variables must be static. If u code like this ,it will work..
public class Test { static transient int maxElements = 100; }
Hope this helps... Jeban [This message has been edited by Jonathan Jeban (edited October 31, 2000).]