lecture11

lecture11 - Class 11 Scope and Access Introduction to...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Introduction to Computation and Problem Solving Prof. Steven R. Lerman and Dr. V. Judson Harward Class 11: Scope and Access 2 Class 11: Scope and Access Introduction to Computation and Problem Solving Prof. Steven R. Lerman and Dr. V. Judson Harward Variable Lifecycles Instance (or object) variables Created when their containing object is created Initialized to default if not explicitly initialized 0 for numbers, false for boolean, null to objects Destroyed when Java garbage collector finds there are no remaining active references to object Static (or class) variables Created when class is first used in program Initialized to default if not explicitly initialized 0 for numbers, false for boolean, null to objects Usually exist for rest of program (unless unloaded) Local variables (or block variables) Created in the statement where they’re defined Not initialized by default. Contain unpredictable data Destroyed when block is exited (at ending brace ) 2 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
3 4 Variable Scope Scope: limiting the parts of the program where a variable or method is defined and visible Prevents collisions between variables and methods in different parts of a program Variables are the big concern, methods are lesser problem Limits effects of changes to smallest possible module or scope Lets multiple people work on large programs simultaneously Allows testing, bug fixing, maintenance to be done while limiting the new bugs introduced 3 Scope: Variables, Methods Local variables (in a method or block) Exist from point of definition to end of block
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 7

lecture11 - Class 11 Scope and Access Introduction to...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online