1. Static Variable:
A static variable is also called as a Class Variable. The static variable gets memory only once at the time of Class Loading. Normally the static variable is also called as the Class variable.
Example:
public class HelloWorld{
static int a = 0;
static String b = "";
static double pi = 3.14;
HelloWorld(int a,String b) {
this.a = a;
this.b = b;
}
public static void main(String[] args) {
double piVal = HelloWorld.pi;//accessing the class variable
System.out.println("Value pi is: "+piVal);
}
}
No comments:
Post a Comment