Khalid says " transient modifier cannot be specified for static variables as they do not belong to objects " . But in one of the answers to mock test i found it can be given ? so can i b or it cannot b given ??
preethi The answer to your question is it depends on the context of the question what I mean is yes you are right a static cannot be transient in other words or correct words a static will not be seralized any way hence use of trasient keyword is not needed hence in a way we can say that static cannot be transient BUT the compiler will not complain if you use transient for a static variable. Hence if the question is asked as if there will be a compiler error then no it won't be which could be the context of the other question. Hope it helped. (see java.io.Serializable api doc it has good detail about this)