# Scope

*noun*

say it: **“scope”** **/skoʊp/**

The part of a program where a name, such as a variable, can be used; outside it, Java doesn't know the name.

## What is **Scope** in Java?

**Scope** — The part of a program where a name can be used.

```java
class WelcomeDesk {
    String messageFor(int guests) {
        if (guests > 0) {
            String message = "Welcome";
            return message;
        }

        return "Closed";
    }
}
```

## In a sentence

- “The variable made inside the loop is out of **scope** after the loop ends, so I declared it before the loop.”

Level: Apprentice · [More Java terms at this level](https://www.ask-codey.com/glossary?category=java&level=2)

Updated: October 26, 2026

## In other subjects

- [Scope in C#](https://www.ask-codey.com/glossary/scope-c-sharp)
- [Scope in JavaScript](https://www.ask-codey.com/glossary/scope-javascript)
- [Scope in PowerShell](https://www.ask-codey.com/glossary/scope-powershell)
- [Scope in Python](https://www.ask-codey.com/glossary/scope)

Source: https://www.ask-codey.com/glossary/scope-java
