Every variable has a specific scope, in which it can be accessed. Every object goes through a life cycle—from creation to garbage collection.
- [Instructor] I've decided to show you…this particular video in the IDE.…Remember that all the links to the code snippets…are available in the handout in the Exercise Files.…Right now I'm in file 02_05.1.…In Java, every data item goes through a lifecycle,…a variable or name starts to exist…when it is created.…A variable scope defines where in the program…the variable is available for reference.…
Here the definition of variable a exists…in two different scopes.…Once in the Main class as instance variable at line three.…And the other time in the print1 method…as an input parameter…which is on line 15.…In this program, we use the two print methods…to print out variable a.…What would this code output?…Let me run it in the IDE and take a look.…
It looks like it compiles correctly.…How did this happen?…Let's trace this program.…The execution starts with the Main method.…We create an object of the Main class…and call its print methods.…We have two definitions of a in this class.…The first definition is an instance variable…
Released
2/8/2019- Data types
- Allowable operations
- Literals and primitives
- Prefixes and suffixes
- Reference types
- Identifier rules
- Conversions
- Casting
Share this video
Embed this video
Video: Reference scope