Posts

Showing posts with the label Scope &Lifetime of variables in java.

Scope and Lifetime of variables in java.

Image
  Scope and Lifetime of variables in java. Scope of a variable : it refers to in which areas or sections of a program can the variable be accessed . Or Scope of a variable  it refers region/location/range in the program where the variable is visible/accessible. Lifetime of a variable: it  refers to how long the variable stays alive in memory. The lifetime of a variable is the time period in which the variable has valid memory. Or Lifetime of a variable : it refers to time duration between variable creation and destroy in memory. There are   three types of variables in java: 1) instance variables : scope of an instance variable  is throughout the class except in static methods.  Lifetime of an instance variable  is until the object stays in memory. 2) class variables : scope of a class variable  is throughout the class.   lifetime of a class variable  is until the end of the program ...