What are static variables?
Are you preparing for IT certification? With practice questions, study notes, interactive quizzes, tips and technical articles, uCertify PrepKits ensure that you get a solid grasp of core technical concepts to ace your certification exam in first attempt.
What are static variables?
Rating:
Variables that have only one copy per class are known as static variables. They are not attached to a particular instance of a class but rather belong to a class as a whole. They are declared by using the static keyword as a modifier. For example:
where, the name of the variable is varIdentifier and its data type is specified by type.
Static variables that are not explicitly initialized in the code are automatically initialized with a default value. The default value depends on the data type of the variables. The table given below shows the default values:
| boolean | false |
| byte | 0 |
| short | 0 |
| int | 0 |
| long | 0L |
| char | 'u0000' |
| float | 0.0F |
| double | 0.0D |
| Object reference | null |
Rating:
Was this information helpful?
Other articles
- What is a finally block?
- What is the toHexString() method of the Integer class?
- What is the Double class?
- What is the setTransactionIsolation() method?
- What is an IllegalStateException?