Skip to main content

Posts

Showing posts with the label static

Static Variable

Static Variable:- A variable which is declared inside class, but outside method with static modifier called static variable. Static variables are used for memory saving purpose or providing facility. Static variable is a class level variable so every object can use static variable and access same value of that variable. So static variable is not related to particular object only. Any object can change the value of static variable and after change every object access new value of variable.static variables can access by two ways one is using the classname.variable and second is object.variable . Static variables can directly access in static method as well as non static method of class. Example1:- Display default value directly. class Student { static String instName; public static void main(String[]args) { System.out.println(instName); } } Output:- C:\JAVATECH>javac Student.java C:\JAVATECH>java Student Null Example2:- Display default value...