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
190k+ students have already unlocked exclusive benefits with Test Prime!

Free Tests

Free
Must Attempt

Current Affairs (Jul 16, 2025 - Jul 23, 2025)

languageIcon English
  • pdpQsnIcon40 Questions
  • pdpsheetsIcon40 Marks
  • timerIcon20 Mins
languageIcon English
Free
Must Attempt

General Awareness Section Test 01

languageIcon English
  • pdpQsnIcon20 Questions
  • pdpsheetsIcon20 Marks
  • timerIcon8 Mins
languageIcon English
Free
Must Attempt

UPSC EPFO Subject Test : Governance and Constitution of India 01

languageIcon English
  • pdpQsnIcon20 Questions
  • pdpsheetsIcon50 Marks
  • timerIcon20 Mins
languageIcon English