Variables
A variable is a container used to store data values. The value of a variable can change while the program is running.
Syntax:
dataType variableName = value;
Example:
int number = 5;
Types of Variables
- Local variables are declared inside methods and used only within them.
- Instance variables are declared inside a class but outside methods.
- Static variables are shared among all objects of a class.
Example:
class Test {
static int count = 10;
}
Top comments (0)