Java programming What is scope Explain the concept and use a
Java programming.
What is scope? Explain the concept and use a class definition along with methods as an example to illustrate the concept. Be sure to include a discussion of static methods.
Solution
Scope of a variable means the part(s) of the program where that variable is accessible.
Example:
class Temp{
private int a;
public int b;
void f(){
int c;
}
}
variable a:
Can be used anywhere inside the class Temp, so its scope is Temp,
variable b:
Can be used anywhere (inside the class Temp or outside it, so its scope is global).
variable c:
Can be used anywhere inside the function f, so its scope is only the function f
