answersLogoWhite

0


Best Answer

Transient Variables are those that do not get serialized during the Serialization process.

A Static variable is one that is mapped to the Class and is not mapped to any object instance and hence they would not get serialized. So, there should be no problem with declaring a transient variable as static.

On the other hand, A final variable is one that's value cannot change. So if you declare a final variable as transient, it would get stored as null during serialization and when you try to de-serialize the variable, you will get errors because, the variable is final and you cannot assign values for it and it is saved as null during serialization.

Result: Yes you can have static transient variables but not final transient variables.

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Can transient variables be declared as 'final' or 'static'?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is a specifier?

a specifier tells the JVM how to treat a particular class,method and variable while executing the program. For example, final classes cannot be extended and final methods cannot be overriden and final variables cannot be changed once declared. Likewise,static methods and variables can be accessed without having to instantiate an object for their class


Why can not define private and protected modifiers for variables in interface?

No. Interface variables are supposed to be public static final. Interfaces, like abstract classes, cannot be instantiated, so all variables in an interface must be static final ones. They are public because usually interfaces are used throughout an application, and this will ensure versatility.


Can static variables be changed?

No, a static variable means that there is only one copy of that variable, and it is shared by all members of the class, or by all callers of a function.A variable that is read-only would be marked as const or final (depending on language).


What is the type of class for which object cannot be created?

A class that is declared as "final" cannot be inherited.


Static method can be overridden?

Depends. A non-static method that is declared final cannot be overridden. A non-static method in a final class cannot be overridden. A non-static method that is declared private cannot be overridden. A non-static method that is declared with package visibility cannot be overridden by classes in a different package. Other than that, yes.

Related questions

What access attribute should static final variables have?

It should be public


What is a specifier?

a specifier tells the JVM how to treat a particular class,method and variable while executing the program. For example, final classes cannot be extended and final methods cannot be overriden and final variables cannot be changed once declared. Likewise,static methods and variables can be accessed without having to instantiate an object for their class


Why can not define private and protected modifiers for variables in interface?

No. Interface variables are supposed to be public static final. Interfaces, like abstract classes, cannot be instantiated, so all variables in an interface must be static final ones. They are public because usually interfaces are used throughout an application, and this will ensure versatility.


How variable in interface is called?

All variables in an interface are by default public static and final and hence they are Constants.


Why do you have only public static final variables in interfaces?

Because of the below reasons:Class implementations can change value of fields if they are not defined as final. Then they would become a part of the implementation. An interface is a pure specification without any implementation, hence they are final to prevent accidental modificationsIf they are static, then they belong to the interface, and not the object, nor the run-time type of the object.An interface provide a way for the client to interact with the object. If variables were not public, the implementing classes would not have access to them.Hence variables in interfaces are public static and final


Are the methods or members of static class static?

A static class may or may not have static members. Adding the static keyword to the class definition won't change this. Note that an inner class which is not static may not contain static members (unless those members are also declared final).


Can static variables be changed?

No, a static variable means that there is only one copy of that variable, and it is shared by all members of the class, or by all callers of a function.A variable that is read-only would be marked as const or final (depending on language).


What is the type of class for which object cannot be created?

A class that is declared as "final" cannot be inherited.


Is unsigned integer constant are available in Java?

yes use the final keyword, normally variables declared final use all capital letters but this is not required final int A = 10;


Can final keyword be applied to static variables and methods?

In the case of variables, the two can be combined. This occurs, for example, with the fields Math.PI and Math.E. I am not sure about methods, but I see no reason why you shouldn't be able to combine the two in this case.


Static method can be overridden?

Depends. A non-static method that is declared final cannot be overridden. A non-static method in a final class cannot be overridden. A non-static method that is declared private cannot be overridden. A non-static method that is declared with package visibility cannot be overridden by classes in a different package. Other than that, yes.


What is the difference between variables and constants in java?

constant is does not change the value of during the excution of programvariable it changes the value during the excution of program