Sobes.tech
Junior — Middle

Where will the link point if a variable is declared but not assigned a value?

sobes.tech AI

Answer from AI

If a reference to an object is declared in Java but not assigned a value, it defaults to null. This means the reference does not point to any object in memory.

Example:

String s; // local variable, not initialized, cannot be used

class Example {
    String s; // class field, defaults to null
}

Important: Local variables must be explicitly initialized before use, otherwise the compiler will generate an error.