From the course: Nail Your Java Interview

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

How is scope used in Java?

How is scope used in Java? - Java Tutorial

From the course: Nail Your Java Interview

Start my 1-month free trial

How is scope used in Java?

- [Lecturer] Depending on the programming language you are working in, the definition of scope can vary. In Java, there's different scopes for different pieces of code. We've already seen this with classes and instances, but let's see how it works with other parts of your program. First, let's talk about parameters. Parameters are how we can pass information to a method in Java. You often see a method definition with inputs. Each of these inputs is called a parameter, and lives only inside the function itself. Let's take a look at this in action. Here, we have a counter class with a count instance attribute, and an instance method that increments the count of a given counter. In the increment count method, amount is a parameter that holds the value that was passed into the function. It's the amount that we want to increment the count instance variable by. If we try to access the amount variable outside of this…

Contents