1. Introduction
A variable is a named memory location used to store data in a Java program.
For example:
int age = 21 ; String name = "Abishek" ; double salary = 25000.50 ;
Enter fullscreen mode
Exit fullscreen mode
In this example:
age stores an integer value.
name stores a String value.
salary stores a decimal value.
Variables are important because they allow us to store, access, and modify data while a program is running.
2. Types of Variables in Java
Java has three main types of variables:
Local Variable
Instance Variable
Static Variable
A. Local Variable
A variable declared inside a method, constructor, or block is called a local variable.
Example:
class Student {
void display ( ) {
int age = 21 ;
System . out . println ( age ) ; }
public static void main ( String [ ] args ) {
Student s1 = new Student ( ) ;
s1 .…