5.8 Scope and Access
Enduring Understanding
To find specific solutions to generalizable problems, programmers include variables in their code so that the same algorithm runs using different input values.
Learning Objective
Explain where variables can be used in the program code.
Essential Knowledge
Local variables can be declared in the body of constructors and methods. These variables may only be used within the constructor or method and cannot be declared to be public or private.
When there is a local variable with the same name as an instance variable, the variable name will refer to the local variable instead of the instance variable.
Formal parameters and variables declared in a method or constructor can only be used within that method or constructor.
Through method decomposition, a programmer breaks down a large problem into smaller subproblems by creating methods to solve each individual subproblem.
Last updated
Was this helpful?