CS 2110 Lecture Notes - Lecture 5: Local Variable
Document Summary
Lecture 5 - scope and inheritance: fields belong to classes, local variables belong inside some block of code. Like in an if statement or method: parameter is inside a method definition, arguments are passed to parameters, example of a local variable. Suppose in some block of code we want to swap the values of b and c. Basically, because we declared temp inside the block of code of the if statement, it only exists inside that block of code. If you tried to write temp = 5 outside that block, and it was not declared outside the if block, then you get an error: note on comments. After that if statement (the one above), we know b <= c, so we can assert that after to be sure our code works: scope of local variables. Scope is the area of code that certain variable/field can be used in.