Types of variables in java
Types of Variables in Java There are three types of variables in Java Local variable Static (or class) variable Instance variable Local variable : These are also called as stack variable. Because they exist in stack memory variable declared inside the body of the method is called local variable. You can use this variable only within that method and the other methods in the class aren't even aware that the variable exists. local variable cannot be defined with " static " keyword. Instance variable: Instance variable are also known as member variable or field A variable declared inside the class but outside the body of the method, is called instance variable. It is not declared as static. Class Variable/Static Variable: • These are loaded and initialized when class is loaded in JVM • There exists only one copy of class variable
Comments