Variables In Java Example
Chapter:
Java Basics
Last Updated:
03-11-2017 12:11:42 UTC
Program:
/* ............... START ............... */
public class JavaVariableExample {
int instance_varialbe = 100; // instance variable
static int val = 100;// static variable
void getValue() {
int local_Variable = 90;// local variable
}
}
/* ............... END ............... */
Notes:
-
Variable is a name of memory location that can contain a data value.
- A variable has a data type.
- There are three types of variables in java: local, instance and static.
- Local Variable : A variable which is declared inside the method is called local variable.
- Instance Variable : A variable which is declared inside the class but outside the method, is called instance variable .
- Static variable : A variable that is declared as static is called static variable. Memory allocation for such variables only happens once when the class is loaded in the memory.
Tags
Variable in Java, Java, Basics