Java variables are containers that store data values. Every program relies on variables to process information.
1. Types of Variables in Java
Java supports three types of variables:
- Local Variables β Declared inside methods
- Instance Variables β Part of object state
- Static Variables β Shared by all objects
2. Example
public class Demo {
int age = 22; // Instance variable
static String city = “Hyderabad”; // Static variable
void show() {
int marks = 85; // Local variable
System.out.println(marks);
}}
3. Quick Tips
- Always initialize your variables.
- Use meaningful names.
- Use camelCase for naming.
