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? - Java Tutorial
From the course: Nail Your Java Interview
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
What's the Java Virtual Machine?2m 21s
-
(Locked)
What's the JDK and JRE?2m 14s
-
(Locked)
What are classes, instances, and constructors?2m 59s
-
(Locked)
What's the difference between static and non-static methods?6m 55s
-
(Locked)
How is scope used in Java?2m 23s
-
(Locked)
How do you access modifiers restrict scope?2m 44s
-
-
-
-
-
-
-