Non‑global variables do not have one universal default visibility; it depends on the language and on where you declare them. Generally, “non‑global” just means “not visible everywhere” and they default to the narrowest scope that their declaration position implies.

Below is a focused breakdown for the most common cases people mean by “non global variables”:

1. Inside a function (locals)

When a variable is declared inside a function or block, it’s usually a local variable.

  • C / C++:
    • int x; inside a function → visible only inside that block or function.
    • Default storage is automatic; visibility is the enclosing block only.
  • Java:
    • Method variables and block variables → visible only inside that method/block; there is no “public/private” for locals.
  • Python:
    • Name bound inside a function → local to that function unless marked global or nonlocal.

So for locals, the “default visibility” is the smallest enclosing block or function.

2. At file / module level but not exported

Many languages support variables that are not global to the whole program , only to the current file or module.

  • C:
    • int x; at top level (no static) → visible across translation units that declare it with extern (truly global).
    • static int x; at file scope → visible only within that one source file (file‑scope “private global”).
  • Java:
    • private static field → visible only inside that class, not the whole program.
  • Modules in other languages (Oberon, etc.):
    • Non‑exported module variables → visible only in that module, not other modules.

In these cases, non‑global usually means “file‑scope” or “module‑scope” variables: their default visibility is that single unit (file/module/class), not the entire program.

3. Class / object fields (not declared public)

For object‑oriented languages, fields that are not global are typically attached to a class or object.

  • Java (and many similar languages):
    • If you omit an access modifier on a field, it defaults to package‑private visibility: visible only to classes in the same package, not everywhere.
* `private` fields → visible only inside the same class.
* `protected` fields → visible in the same package and in subclasses.
* `public` fields → visible from anywhere.

So “non‑global” class members default to some restricted form (package, class, or subclass), depending on the language’s default modifier rules.

4. Conceptual answer (interview / theory style)

If the question is conceptual—“to what visibility do non global variables default?”—a safe, language‑agnostic way to phrase it is:

Non‑global variables default to the narrowest scope implied by where they are declared (block, function, class, module, or file) and are not visible outside that scope unless the language provides a way to export or widen access.

In other words, their default visibility is local to their defining scope , not program‑wide.