9-Variables and Methods - Scopes
9-Variables and Methods - Scopes
In Java, variables and methods have different scopes depending on where and how they are
declared. The four main scopes are:
1. Instance Scope (Object-level)
2. Static Scope (Class-level)
3. Local Scope (Method-level)
4. Block Scope (Inside Loops/Blocks)
void show() {
System.out.println("Instance Variable: " + instanceVar);
}
}
void show() {
System.out.println("Instance Variable: " + instanceVar + ", Static Variable: " +
staticVar);
}
Summary Table