Which of the following statements are true about a variable created with the static modifier?
1) Once assigned the value of a static variable may not be altered
2) A static variable created in a method will keep the same value between calls
3) Only one instance of a static variable will exist for any amount of class instances
4) The static modifier can only be applied to a primitive value
Answer :
3) Only one instance of a static variable will exist for any amount of class instances
Option 1) is more a description of a final variable. Option 2 is designed to fool Visual Basic programmers like me as this is how you can use the keyword static in VB. The modifier static can be applied to a class, method or variable.
No comments:
Post a Comment