In this video, Doug Winnie demonstrates how scope affects access to variables and methods within your code. Scope is a set of rules that define where and how you can access variables and values in various locations of your code.
- [Instructor] The scope of a variable or a method…is based on where it's defined.…This means that if a variable is defined…in a function or method,…it isn't available for you to use outside of the function.…I created some code for us to get started…to look at how scope can affect access to your variables.…If you open up the project for this movie,…you'll see the following code.…There are three main things I want to point out in this code…and you'll modify it to illustrate each point.…The first is at the top…where we have a variable called outsideValue.…
In this variable is a number with the value five.…Immediately after that, we have the constructor.…In this are two System.out calls…to output two variables to the console.…The first is the outsideValue that we just created.…The second is the variable functionValue…that is defined inside the function myFunction…that starts later in the code.…If we try to build and run the program,…we will get two errors.…Let's focus on the first error for now.…
We get this error located on line 12, rows 53…
- The history of Java
- Setting up your development environment
- Working with values and variables
- Using methods and functions
- Capturing user input
- Creating conditional tests
- Using loops
- Creating and changing arrays
- Object-oriented programming in Java
- Defining permissions
- Extending classes
Skill Level Beginner
Computer Science Principles: The Internetwith Doug Winnie59m 30s Beginner
Java Essential Training for Studentswith Peggy Fisher3h 6m Intermediate
1. Intro to Java
2. Define Actions Using Code
3. Repeat Actions and Test for Conditions
4. Object-Oriented Programming Basics
Next steps1m 44s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.