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.

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

Updated

In other subjects