Types of Variables

Variables are used to store and manipulate data. There are several types of variables in Java, which can be categorized into three main groups:
#Q
Instance Variables (Non-Static Variables) ::

public class MyClass {
    int instanceVar; // instance variable
}

#/Q

#Q
Static Variables (Class Variables)::

public class MyClass {
    static int staticVar; // static variable
}

#/Q

#Q
Local Variables::

public void myMethod() {
    int localVar; // local variable
}

#/Q

#Q
Parameters (Method or Constructor Parameters)::

public void myMethod(int parameter) {
    // 'parameter' is a method parameter
}

#/Q

#Q
Array Elements::

int[] numbers = {1, 2, 3}; // Array elements are variables
int value = numbers[0]; // Accessing an array element

#/Q

Tip

Static method means that it can be accessed without creating an object of the class.