Search Interview Questions | ![]() ![]() Click here and help us by providing the answer. ![]() Click Correct / Improve and please let us know. |
|
| ||||
Core Java - Interview Questions and Answers for 'Static variable' - 7 question(s) found - Order By Newest | ||||
| ||||
Ans. Advantages Can do meta object operations ( like validating something before creating objects , keep count of number of objects ) Can do operations which have nothing to do with objects but still you want them to be tied to Class. Disadvantages Commonly used to static variables sometime leads to problems due to access by different objects. Are not tied to objects so doesn't reflect pure Object Oriented approach. Needs to be synchronized so as to avoid update conflicts by mutiple objects and threads. Some limitation in testing as not all frameworks have facility to mock them. Powermock has but Mockito doesnt | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. They are loaded at runtime when the respective Class is loaded. | ||||
![]() | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. No. Only Object and its members are serialized. Static variables are shared variables and doesn't correspond to a specific object. | ||||
![]() | ||||
![]() ![]() ![]() ![]() ![]() ![]() | ||||
![]() | ||||
| ||||
Ans. It is a class level variable that is shared among the objects of that class. | ||||
![]() | ||||
![]() ![]() ![]() ![]() ![]() ![]() | ||||
![]() | ||||
| ||||
Ans. static methods and static elements are shared by all objects of a class and hence could create problem. Static methods are not synchronized by default and hence could create problem when accessed through multiple threads. Static elements are shareable by class and hence state of one object could be altered by another object. Some limitations with Unit testing as not all mocking framework facilitate mocking them. Power mock allows but Mockito doesn't | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. Cloneable and Serializable are Marker Interfaces, So these are empty interfaces with no variables. | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. Yes the value of a static variable can be changed. It's the final keyword that restrict the modification of value not static. | ||||
![]() | ||||
![]() ![]() ![]() | ||||