JAVA

Scope and Default Values of Variables

Scope of variables

A variables scope is the region of a program within the variable Can be referred by its simple name.
Scope also determines when the system creates and destroys memory for the variables.
The location of the variables declaration within your program establish its scope and places it into one of these our categories.

  1. Member variable
  2. Local variable
  3. Method parameter
  4. exception-handler parameter

Default variable initialization

if you are not assigning value then java runtime assigns default value to variable and when you try to access the variable you get the default value of the variable.

Following table shows variables types and their default values.

Data Types    Default value
Boolean  False
char \u0000
int    0/ 0l
float 0.0f / 0.0d
any reference  type null



Subscribe us on Youtube

Share This Page on


Ask Question