Written by the Fiveable Content Team โข Last updated September 2025
Verified for the 2026 exam
Verified for the 2026 examโขWritten by the Fiveable Content Team โข Last updated September 2025
Definition
A local variable is a variable that is declared inside a method or block and can only be accessed within that particular method or block. It has limited scope and lifetime, meaning it only exists as long as the method or block is being executed.
An instance variable is declared within a class but outside any methods, and it belongs to an instance (object) of that class. It can be accessed by any method within the same class.
A parameter is a special kind of local variable used in method declarations to receive values from outside when calling that method. It allows data to be passed into methods.
Global Variable: Unlike local variables, global variables are declared at the beginning of the program and are accessible from anywhere in the code. They have wider scope than local variables.