Technology News, Online Income, Gadgets, Reviews

Technology News, Gadgets and Reviews

Translate

Breaking

Total Pageviews

Wednesday, January 18, 2023

Java Static Variable

   Java Variable 

A variable is a container which holds the value while the java program is executed. A variable is assigned with a data type. and we can't create a single variable without type. 

Variable is a name of memory location. There are three types of variables in java: local, instance and static.

In this tutorial we are going to java Static variable.


   Java Static Variable 


A variable that is declared as static is called a static variable. You can create a single copy of the static variable and share it among all the instances of the class. Memory allocation for static variables happens only once when the class is loaded in the memory.


Example : 

Class Test{

static int i =10;   // Static Variable

public static void main(String [] args){

System.out.println(i);  //  10

 }

    }


No comments:

Post a Comment