From the course: Java Cheat Codes: Most Popular Functions
Unlock this course with a free trial
Join today to access over 25,500 courses taught by industry experts.
Java scope - Java Tutorial
From the course: Java Cheat Codes: Most Popular Functions
Java scope
- [Instructor] Java Scope. Java has different levels of accessibility, i.e. scope, for variables and methods in Java. Let's look into what those are. You have local scope. This is when variables and methods are declared within a block of code, which could be a method, a loop, or conditional statement. And for accessibility, you can only access it within that specific block. In this example here, you have the local variable, which I just named local variable, and the conditional statement, which is local to this specific if block. And then you have class scope. This is when variables and methods are declared within a class, but outside any specific method. For accessibility, it's accessible from any method within the same class. So for example, we have the class variable, named class variable, and then you can access this method just within this class. And the my method is specifically for the my class class. Next we have package scope, could also be called the default scope. This is…