Variable in Java:
A variable is a named storage location used to hold a value of a particular data type.
For example:
int age = 20;
String name = "Gowtham";
Here:
int is the data type.
age is the variable name.
20 is the value stored in the variable.
String is the type used to represent text.
name is the variable name.
"Gowtham" is the text value.
Types of Variables in Java
Java has three main categories of variables based on where they are declared.
1. Local Variable
A local variable is declared inside a method, constructor, or block.
void display() {
int age = 20;
System.out.println(age);
}
2. Instance Variable
An instance variable is declared inside a class but outside methods. Each object has its own instance fields.
class Student {
String name = "Gowtham";
int age = 20;
}
3.…