Can we declare static variables as transient ?

Search Interview Questions

 More than 3000 questions in repository.
 There are more than 900 unanswered questions.
Click here and help us by providing the answer.
 Have a video suggestion.
Click Correct / Improve and please let us know.
Label / Company      Label / Company / Text


Interview Questions and Answers

 Q1. Can we declare static variables as transient ?Core Java
Ans. It's weird that compiler doesn't complain if we declare transient with static variable because it makes no sense. At least a warning message saying "transient is useless in this situation" would have helped with code cleaning.

Static variables are never serialized and transient is an indication that the specified variable shouldn't be serialized so its kind of double enforcement not to serialize.

It could be that as it makes no different to the variable behavior and hence using both keywords with a variable are permitted.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     static  transient  serialization     Asked in 1 Companies      expert        rare

Try 1 Question(s) Test

Related Questions

  Which of the following combination of keywords is illegal in Java ?

a. static and transient
b. transient and final
c. static and synchronized
d. abstract and final
  Which keyword is used to provide explicit access of a code block to single thread ?

a. Transient
b. Final
c. Explicit
d. Synchronized
  What is the use of Transient Keyword ?
  What are transient variables in java?
  Which of the following is true ?
  Variables of an interface are intrinsically ...

a. transient
b. final
c. public
d. static

Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.

Company Name:
Questions Asked: