CS 2110 Lecture Notes - Lecture 5: Local Variable

74 views3 pages
14 Jun 2017
Course
Professor

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.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents