Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

can a trasient member also b static ??

 
preethi subramaniam
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ??
 
Lawrence Chettiar
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
Jessica Sant
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
whew -- I think I'm "hence" 'd out.
Check out our handy dandy search facility -- you'll find this has been asked a bunch.
Here's a couple to get you started:
transient static variable
transient + static
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic