hamburger menu
All Coursesall course arrow
adda247
reward-icon
adda247
    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
    175k+ students have already unlocked exclusive benefits with Test Prime!

    Free Tests

    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
    Free
    Must Attempt

    CBI Apprentice English Section Test -1

    languageIcon English
    • pdpQsnIcon15 Questions
    • pdpsheetsIcon15 Marks
    • timerIcon10 Mins
    languageIcon English