arrow
arrow
arrow
What is the default value of a static variable of type int in Java if not explicitly initialized?
Question



What is the default value of a static variable of type int in Java if not explicitly initialized?

A.

null

B.

0

C.

-1

D.

undefined

E.

garbage value

Correct option is B

In Java, static variables belong to the class rather than an instance and are initialized with default values if not explicitly set. For int variables, the default value is 0.
Example:

Important Key Points:
1. Default values for static variables are determined by the type:
· int: 0
· double: 0.0
· boolean: false
· Object references: null
2. static variables are stored in the method area of the JVM.
Knowledge Booster:
· null: Applicable for object references, not primitive types.
· -1: Not the default value for any type in Java.
· undefined: Java does not use the concept of "undefined"; default values are well-defined.
· garbage value: Java does not allow uninitialized variables to have garbage values.

test-prime-package

Access ‘SEBI Grade-A Assistant Manager’ Mock Tests with

  • 60000+ Mocks and Previous Year Papers
  • Unlimited Re-Attempts
  • Personalised Report Card
  • 500% Refund on Final Selection
  • Largest Community
students-icon
174k+ students have already unlocked exclusive benefits with Test Prime!

Free Tests

Free
Must Attempt

Current Affairs (Jun 24, 2025 - Jun 30, 2025)

languageIcon English
  • pdpQsnIcon35 Questions
  • pdpsheetsIcon35 Marks
  • timerIcon15 Mins
languageIcon English
Free
Must Attempt

grammar

languageIcon English
  • pdpQsnIcon10 Questions
  • pdpsheetsIcon10 Marks
  • timerIcon7 Mins
languageIcon English
Free
Must Attempt

Series

languageIcon English
  • pdpQsnIcon10 Questions
  • pdpsheetsIcon10 Marks
  • timerIcon8 Mins
languageIcon English